From c3882a16496b58a10fd64aca84310f426f84dced Mon Sep 17 00:00:00 2001 From: Micah Denbraver Date: Wed, 8 May 2024 12:36:43 -0700 Subject: [PATCH] use pytest's `tmp_path` --- tests/test_pip_compat.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/test_pip_compat.py b/tests/test_pip_compat.py index 451ba9b3..1eea3c82 100644 --- a/tests/test_pip_compat.py +++ b/tests/test_pip_compat.py @@ -12,21 +12,18 @@ from .constants import PACKAGES_RELATIVE_PATH -def test_parse_requirements_preserve_editable_relative_path(repository): +def test_parse_requirements_preserve_editable_relative_path(tmp_path, repository): test_package_path = str( PurePosixPath(Path(PACKAGES_RELATIVE_PATH)) / "small_fake_a" ) + requirements_in_path = str(tmp_path / "requirements.in") - infile = tempfile.NamedTemporaryFile("w", delete=False) - try: + with open(requirements_in_path, 'w') as infile: infile.write(f"-e {test_package_path}") - infile.close() - [install_requirement] = parse_requirements( - infile.name, session=repository.session - ) - finally: - os.unlink(infile.name) + [install_requirement] = parse_requirements( + requirements_in_path, session=repository.session + ) assert install_requirement.link.url == test_package_path assert install_requirement.link.file_path == test_package_path