diff --git a/pyproject.toml b/pyproject.toml index 405dec981..f1a3e5c52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,6 +67,7 @@ extend-select = [ "TCH", # flake8-type-checking "TID", # flake8-tidy-imports "UP", # pyupgrade + "PTH", # flake8-use-pathlib ] ignore = [ "B904", # use 'raise ... from err' diff --git a/src/poetry/core/masonry/api.py b/src/poetry/core/masonry/api.py index 42ece0b96..a712baf91 100644 --- a/src/poetry/core/masonry/api.py +++ b/src/poetry/core/masonry/api.py @@ -39,7 +39,7 @@ def get_requires_for_build_wheel( def prepare_metadata_for_build_wheel( metadata_directory: str, config_settings: dict[str, Any] | None = None ) -> str: - poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False) + poetry = Factory().create_poetry(Path().resolve(), with_groups=False) builder = WheelBuilder(poetry) metadata_path = Path(metadata_directory) dist_info = builder.prepare_metadata(metadata_path) @@ -52,7 +52,7 @@ def build_wheel( metadata_directory: str | None = None, ) -> str: """Builds a wheel, places it in wheel_directory""" - poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False) + poetry = Factory().create_poetry(Path().resolve(), with_groups=False) metadata_path = None if metadata_directory is None else Path(metadata_directory) return WheelBuilder.make_in( @@ -64,7 +64,7 @@ def build_sdist( sdist_directory: str, config_settings: dict[str, Any] | None = None ) -> str: """Builds an sdist, places it in sdist_directory""" - poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False) + poetry = Factory().create_poetry(Path().resolve(), with_groups=False) path = SdistBuilder(poetry).build(Path(sdist_directory)) @@ -76,7 +76,7 @@ def build_editable( config_settings: dict[str, Any] | None = None, metadata_directory: str | None = None, ) -> str: - poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False) + poetry = Factory().create_poetry(Path().resolve(), with_groups=False) metadata_path = None if metadata_directory is None else Path(metadata_directory) return WheelBuilder.make_in( diff --git a/src/poetry/core/masonry/builders/sdist.py b/src/poetry/core/masonry/builders/sdist.py index 02bfcc9d1..a22ce9574 100644 --- a/src/poetry/core/masonry/builders/sdist.py +++ b/src/poetry/core/masonry/builders/sdist.py @@ -141,7 +141,7 @@ def build_setup(self) -> bytes: pkg_root = os.path.relpath(pkg_dir, str(self._path)) if "" in package_dir: package_dir.update( - (p, os.path.join(pkg_root, p.replace(".", "/"))) + (p, (Path(pkg_root) / p.replace(".", "/")).as_posix()) for p in _packages ) else: @@ -258,18 +258,18 @@ def find_packages( subpkg_paths = set() def find_nearest_pkg(rel_path: str) -> tuple[str, str]: - parts = rel_path.split(os.sep) + parts = Path(rel_path).parts for i in reversed(range(1, len(parts))): ancestor = "/".join(parts[:i]) if ancestor in subpkg_paths: - pkg = ".".join([pkg_name] + parts[:i]) + pkg = ".".join([pkg_name, *parts[:i]]) return pkg, "/".join(parts[i:]) # Relative to the top-level package return pkg_name, Path(rel_path).as_posix() - for path, _dirnames, filenames in os.walk(str(base), topdown=True): - if os.path.basename(path) == "__pycache__": + for path, _dirnames, filenames in os.walk(base, topdown=True): + if Path(path).name == "__pycache__": continue from_top_level = os.path.relpath(path, base) @@ -285,7 +285,7 @@ def find_nearest_pkg(rel_path: str) -> tuple[str, str]: ) if is_subpkg: subpkg_paths.add(from_top_level) - parts = from_top_level.split(os.sep) + parts = Path(from_top_level).parts packages.append(".".join([pkg_name, *parts])) else: pkg, from_nearest_pkg = find_nearest_pkg(from_top_level) diff --git a/src/poetry/core/masonry/builders/wheel.py b/src/poetry/core/masonry/builders/wheel.py index 692c189f2..bc74d50ff 100644 --- a/src/poetry/core/masonry/builders/wheel.py +++ b/src/poetry/core/masonry/builders/wheel.py @@ -104,11 +104,12 @@ def build( if not target_dir.exists(): target_dir.mkdir(parents=True) - fd, temp_path = tempfile.mkstemp(suffix=".whl") + fd, temp = tempfile.mkstemp(suffix=".whl") - st_mode = os.stat(temp_path).st_mode + temp_path = Path(temp) + st_mode = temp_path.stat().st_mode new_mode = normalize_file_permissions(st_mode) - os.chmod(temp_path, new_mode) + temp_path.chmod(new_mode) with os.fdopen(fd, "w+b") as fd_file, zipfile.ZipFile( fd_file, mode="w", compression=zipfile.ZIP_DEFLATED @@ -137,7 +138,7 @@ def build( wheel_path = target_dir / self.wheel_filename if wheel_path.exists(): wheel_path.unlink() - shutil.move(temp_path, str(wheel_path)) + shutil.move(str(temp_path), str(wheel_path)) logger.info(f"Built {self.wheel_filename}") return wheel_path diff --git a/src/poetry/core/packages/dependency.py b/src/poetry/core/packages/dependency.py index 5f3f569ff..9c40a7ae0 100644 --- a/src/poetry/core/packages/dependency.py +++ b/src/poetry/core/packages/dependency.py @@ -396,9 +396,9 @@ def create_from_pep_508( elif req.url: link = Link(req.url) else: - path_str = os.path.normpath(os.path.abspath(name)) + path_str = os.path.normpath(os.path.abspath(name)) # noqa: PTH100 p, extras = strip_extras(path_str) - if os.path.isdir(p) and (os.path.sep in name or name.startswith(".")): + if p.is_dir() and (os.path.sep in name or name.startswith(".")): if not is_python_project(Path(name)): raise ValueError( f"Directory {name!r} is not installable. Not a Python project." diff --git a/src/poetry/core/packages/utils/utils.py b/src/poetry/core/packages/utils/utils.py index 1745853c6..271e1e2d8 100644 --- a/src/poetry/core/packages/utils/utils.py +++ b/src/poetry/core/packages/utils/utils.py @@ -1,7 +1,6 @@ from __future__ import annotations import functools -import posixpath import re import sys @@ -106,7 +105,7 @@ def is_url(name: str) -> bool: ] -def strip_extras(path: str) -> tuple[str, str | None]: +def strip_extras(path: str) -> tuple[Path, str | None]: m = re.match(r"^(.+)(\[[^\]]+\])$", path) extras = None if m: @@ -115,7 +114,7 @@ def strip_extras(path: str) -> tuple[str, str | None]: else: path_no_extras = path - return path_no_extras, extras + return Path(path_no_extras), extras @functools.lru_cache(maxsize=None) @@ -133,17 +132,19 @@ def is_python_project(path: Path) -> bool: return pyproject or setuptools_project -def is_archive_file(name: str) -> bool: +def is_archive_file(name: str | Path) -> bool: """Return True if `name` is a considered as an archive file.""" ext = splitext(name)[1].lower() return ext in ARCHIVE_EXTENSIONS -def splitext(path: str) -> tuple[str, str]: - """Like os.path.splitext, but take off .tar too""" - base, ext = posixpath.splitext(path) +def splitext(path: str | Path) -> tuple[str, str]: + """Like pathlib.Path.stem and suffix, but take off .tar too""" + if isinstance(path, str): + path = Path(path) + base, ext = path.stem, path.suffix if base.lower().endswith(".tar"): - ext = base[-4:] + ext + ext = f"{base[-4:]}{ext}" base = base[:-4] return base, ext diff --git a/src/poetry/core/utils/helpers.py b/src/poetry/core/utils/helpers.py index 7306973f5..aa5354feb 100644 --- a/src/poetry/core/utils/helpers.py +++ b/src/poetry/core/utils/helpers.py @@ -1,6 +1,5 @@ from __future__ import annotations -import os import shutil import stat import sys @@ -29,16 +28,16 @@ def module_name(name: str) -> str: @contextmanager -def temporary_directory(*args: Any, **kwargs: Any) -> Iterator[str]: +def temporary_directory(*args: Any, **kwargs: Any) -> Iterator[Path]: if sys.version_info >= (3, 10): # mypy reports an error if ignore_cleanup_errors is # specified literally in the call kwargs["ignore_cleanup_errors"] = True with tempfile.TemporaryDirectory(*args, **kwargs) as name: - yield name + yield Path(name) else: name = tempfile.mkdtemp(*args, **kwargs) - yield name + yield Path(name) robust_rmtree(name) @@ -80,10 +79,11 @@ def parse_requires(requires: str) -> list[str]: def _on_rm_error(func: Any, path: str | Path, exc_info: Any) -> None: - if not os.path.exists(path): + path = Path(path) + if not path.exists(): return - os.chmod(path, stat.S_IWRITE) + path.chmod(stat.S_IWRITE) func(path) diff --git a/tests/integration/test_pep517_backend.py b/tests/integration/test_pep517_backend.py index 7824bd0ae..fe6c7364b 100644 --- a/tests/integration/test_pep517_backend.py +++ b/tests/integration/test_pep517_backend.py @@ -38,7 +38,9 @@ def test_pip_install( # Append dynamic `build-system` section to `pyproject.toml` in the temporary # project directory. - with open(temp_pep_517_backend_path / "pyproject.toml", "a", encoding="utf-8") as f: + with (temp_pep_517_backend_path / "pyproject.toml").open( + mode="a", encoding="utf-8" + ) as f: f.write( BUILD_SYSTEM_TEMPLATE.format(project_path=project_source_root.as_posix()) ) diff --git a/tests/masonry/builders/test_complete.py b/tests/masonry/builders/test_complete.py index 80f86459a..76499b072 100644 --- a/tests/masonry/builders/test_complete.py +++ b/tests/masonry/builders/test_complete.py @@ -1,7 +1,6 @@ from __future__ import annotations import csv -import os import platform import re import shutil @@ -121,7 +120,7 @@ def test_complete(project: str, no_vcs: bool) -> None: assert whl.exists() if sys.platform != "win32": - assert (os.stat(str(whl)).st_mode & 0o777) == 0o644 + assert (whl.stat().st_mode & 0o777) == 0o644 expected_name_list = [ "my_package/__init__.py", diff --git a/tests/masonry/builders/test_sdist.py b/tests/masonry/builders/test_sdist.py index 6a9e60d19..2f7ca08cb 100644 --- a/tests/masonry/builders/test_sdist.py +++ b/tests/masonry/builders/test_sdist.py @@ -339,7 +339,7 @@ def test_setup_py_context(project_name: str) -> None: assert setup.exists() assert project_setup_py == setup - with open(str(setup), "rb") as f: + with setup.open(mode="rb") as f: # we convert to string and replace line endings here for compatibility data = f.read().decode().replace("\r\n", "\n") assert data == builder.build_setup().decode() diff --git a/tests/masonry/test_api.py b/tests/masonry/test_api.py index 95c73a660..49a56818c 100644 --- a/tests/masonry/test_api.py +++ b/tests/masonry/test_api.py @@ -23,7 +23,7 @@ @contextmanager def cwd(directory: str | Path) -> Iterator[None]: - prev = os.getcwd() + prev = Path.cwd() os.chdir(str(directory)) try: yield @@ -31,58 +31,54 @@ def cwd(directory: str | Path) -> Iterator[None]: os.chdir(prev) -fixtures = os.path.join(os.path.dirname(__file__), "builders", "fixtures") +fixtures = Path(__file__).parent / "builders" / "fixtures" @pytest.mark.parametrize("project", ["complete", "complete_new"]) def test_get_requires_for_build_wheel(project: str) -> None: expected: list[str] = [] - with cwd(os.path.join(fixtures, project)): + with cwd(fixtures / project): assert api.get_requires_for_build_wheel() == expected @pytest.mark.parametrize("project", ["complete", "complete_new"]) def test_get_requires_for_build_sdist(project: str) -> None: expected: list[str] = [] - with cwd(os.path.join(fixtures, project)): + with cwd(fixtures / project): assert api.get_requires_for_build_sdist() == expected @pytest.mark.parametrize("project", ["complete", "complete_new"]) def test_build_wheel(project: str) -> None: - with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, project)): - filename = api.build_wheel(tmp_dir) + with temporary_directory() as tmp_dir, cwd(fixtures / project): + filename = api.build_wheel(str(tmp_dir)) validate_wheel_contents( name="my_package", version="1.2.3", - path=str(os.path.join(tmp_dir, filename)), + path=tmp_dir / filename, files=["entry_points.txt"], ) def test_build_wheel_with_include() -> None: - with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, "with-include")): - filename = api.build_wheel(tmp_dir) + with temporary_directory() as tmp_dir, cwd(fixtures / "with-include"): + filename = api.build_wheel(str(tmp_dir)) validate_wheel_contents( name="with_include", version="1.2.3", - path=str(os.path.join(tmp_dir, filename)), + path=tmp_dir / filename, files=["entry_points.txt"], ) def test_build_wheel_with_bad_path_dev_dep_succeeds() -> None: - with temporary_directory() as tmp_dir, cwd( - os.path.join(fixtures, "with_bad_path_dev_dep") - ): - api.build_wheel(tmp_dir) + with temporary_directory() as tmp_dir, cwd(fixtures / "with_bad_path_dev_dep"): + api.build_wheel(str(tmp_dir)) def test_build_wheel_with_bad_path_dep_succeeds(caplog: LogCaptureFixture) -> None: - with temporary_directory() as tmp_dir, cwd( - os.path.join(fixtures, "with_bad_path_dep") - ): - api.build_wheel(tmp_dir) + with temporary_directory() as tmp_dir, cwd(fixtures / "with_bad_path_dep"): + api.build_wheel(str(tmp_dir)) assert len(caplog.records) == 1 record = caplog.records[0] assert record.levelname == "WARNING" @@ -90,48 +86,44 @@ def test_build_wheel_with_bad_path_dep_succeeds(caplog: LogCaptureFixture) -> No def test_build_wheel_extended() -> None: - with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, "extended")): - filename = api.build_wheel(tmp_dir) + with temporary_directory() as tmp_dir, cwd(fixtures / "extended"): + filename = api.build_wheel(str(tmp_dir)) whl = Path(tmp_dir) / filename assert whl.exists() - validate_wheel_contents(name="extended", version="0.1", path=whl.as_posix()) + validate_wheel_contents(name="extended", version="0.1", path=whl) @pytest.mark.parametrize("project", ["complete", "complete_new"]) def test_build_sdist(project: str) -> None: - with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, project)): - filename = api.build_sdist(tmp_dir) + with temporary_directory() as tmp_dir, cwd(fixtures / project): + filename = api.build_sdist(str(tmp_dir)) validate_sdist_contents( name="my-package", version="1.2.3", - path=str(os.path.join(tmp_dir, filename)), + path=tmp_dir / filename, files=["LICENSE"], ) def test_build_sdist_with_include() -> None: - with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, "with-include")): - filename = api.build_sdist(tmp_dir) + with temporary_directory() as tmp_dir, cwd(fixtures / "with-include"): + filename = api.build_sdist(str(tmp_dir)) validate_sdist_contents( name="with-include", version="1.2.3", - path=str(os.path.join(tmp_dir, filename)), + path=tmp_dir / filename, files=["LICENSE"], ) def test_build_sdist_with_bad_path_dev_dep_succeeds() -> None: - with temporary_directory() as tmp_dir, cwd( - os.path.join(fixtures, "with_bad_path_dev_dep") - ): - api.build_sdist(tmp_dir) + with temporary_directory() as tmp_dir, cwd(fixtures / "with_bad_path_dev_dep"): + api.build_sdist(str(tmp_dir)) def test_build_sdist_with_bad_path_dep_succeeds(caplog: LogCaptureFixture) -> None: - with temporary_directory() as tmp_dir, cwd( - os.path.join(fixtures, "with_bad_path_dep") - ): - api.build_sdist(tmp_dir) + with temporary_directory() as tmp_dir, cwd(fixtures / "with_bad_path_dep"): + api.build_sdist(str(tmp_dir)) assert len(caplog.records) == 1 record = caplog.records[0] assert record.levelname == "WARNING" @@ -194,8 +186,8 @@ def test_prepare_metadata_for_build_wheel(project: str) -> None: ========== """ - with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, project)): - dirname = api.prepare_metadata_for_build_wheel(tmp_dir) + with temporary_directory() as tmp_dir, cwd(fixtures / project): + dirname = api.prepare_metadata_for_build_wheel(str(tmp_dir)) assert dirname == "my_package-1.2.3.dist-info" @@ -216,19 +208,15 @@ def test_prepare_metadata_for_build_wheel(project: str) -> None: def test_prepare_metadata_for_build_wheel_with_bad_path_dev_dep_succeeds() -> None: - with temporary_directory() as tmp_dir, cwd( - os.path.join(fixtures, "with_bad_path_dev_dep") - ): - api.prepare_metadata_for_build_wheel(tmp_dir) + with temporary_directory() as tmp_dir, cwd(fixtures / "with_bad_path_dev_dep"): + api.prepare_metadata_for_build_wheel(str(tmp_dir)) def test_prepare_metadata_for_build_wheel_with_bad_path_dep_succeeds( caplog: LogCaptureFixture, ) -> None: - with temporary_directory() as tmp_dir, cwd( - os.path.join(fixtures, "with_bad_path_dep") - ): - api.prepare_metadata_for_build_wheel(tmp_dir) + with temporary_directory() as tmp_dir, cwd(fixtures / "with_bad_path_dep"): + api.prepare_metadata_for_build_wheel(str(tmp_dir)) assert len(caplog.records) == 1 record = caplog.records[0] assert record.levelname == "WARNING" @@ -237,16 +225,15 @@ def test_prepare_metadata_for_build_wheel_with_bad_path_dep_succeeds( @pytest.mark.parametrize("project", ["complete", "complete_new"]) def test_build_editable_wheel(project: str) -> None: - pkg_dir = Path(fixtures) / project - + pkg_dir = fixtures / project with temporary_directory() as tmp_dir, cwd(pkg_dir): - filename = api.build_editable(tmp_dir) + filename = api.build_editable(str(tmp_dir)) wheel_pth = Path(tmp_dir) / filename validate_wheel_contents( name="my_package", version="1.2.3", - path=str(wheel_pth), + path=wheel_pth, ) with zipfile.ZipFile(wheel_pth) as z: @@ -258,23 +245,23 @@ def test_build_editable_wheel(project: str) -> None: @pytest.mark.parametrize("project", ["complete", "complete_new"]) def test_build_wheel_with_metadata_directory(project: str) -> None: - pkg_dir = Path(fixtures) / project + pkg_dir = fixtures / project with temporary_directory() as metadata_tmp_dir, cwd(pkg_dir): - metadata_directory = api.prepare_metadata_for_build_wheel(metadata_tmp_dir) + metadata_directory = api.prepare_metadata_for_build_wheel(str(metadata_tmp_dir)) with temporary_directory() as wheel_tmp_dir: dist_info_path = Path(metadata_tmp_dir) / metadata_directory (dist_info_path / "CUSTOM").touch() filename = api.build_wheel( - wheel_tmp_dir, metadata_directory=str(dist_info_path) + str(wheel_tmp_dir), metadata_directory=str(dist_info_path) ) wheel_pth = Path(wheel_tmp_dir) / filename validate_wheel_contents( name="my_package", version="1.2.3", - path=str(wheel_pth), + path=wheel_pth, files=["entry_points.txt"], ) @@ -286,23 +273,25 @@ def test_build_wheel_with_metadata_directory(project: str) -> None: @pytest.mark.parametrize("project", ["complete", "complete_new"]) def test_build_editable_wheel_with_metadata_directory(project: str) -> None: - pkg_dir = Path(fixtures) / project + pkg_dir = fixtures / project with temporary_directory() as metadata_tmp_dir, cwd(pkg_dir): - metadata_directory = api.prepare_metadata_for_build_editable(metadata_tmp_dir) + metadata_directory = api.prepare_metadata_for_build_editable( + str(metadata_tmp_dir) + ) with temporary_directory() as wheel_tmp_dir: dist_info_path = Path(metadata_tmp_dir) / metadata_directory (dist_info_path / "CUSTOM").touch() filename = api.build_editable( - wheel_tmp_dir, metadata_directory=str(dist_info_path) + str(wheel_tmp_dir), metadata_directory=str(dist_info_path) ) wheel_pth = Path(wheel_tmp_dir) / filename validate_wheel_contents( name="my_package", version="1.2.3", - path=str(wheel_pth), + path=wheel_pth, files=["entry_points.txt"], ) diff --git a/tests/packages/utils/test_utils_urls.py b/tests/packages/utils/test_utils_urls.py index 6480c78a8..0f2814ed1 100644 --- a/tests/packages/utils/test_utils_urls.py +++ b/tests/packages/utils/test_utils_urls.py @@ -16,7 +16,7 @@ @pytest.mark.skipif("sys.platform == 'win32'") def test_path_to_url_unix() -> None: assert path_to_url("/tmp/file") == "file:///tmp/file" - path = Path(".") / "file" + path = Path() / "file" assert path_to_url("file") == "file://" + path.absolute().as_posix() @@ -25,7 +25,7 @@ def test_path_to_url_win() -> None: assert path_to_url("c:/tmp/file") == "file:///c:/tmp/file" assert path_to_url("c:\\tmp\\file") == "file:///c:/tmp/file" assert path_to_url(r"\\unc\as\path") == "file://unc/as/path" - path = Path(".") / "file" + path = Path() / "file" assert path_to_url("file") == "file:///" + path.absolute().as_posix() diff --git a/tests/testutils.py b/tests/testutils.py index f809f63bd..145dd3eb1 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -69,20 +69,19 @@ def subprocess_run(*args: str, **kwargs: Any) -> subprocess.CompletedProcess[str def validate_wheel_contents( - name: str, version: str, path: str, files: list[str] | None = None + name: str, version: str, path: Path, files: list[str] | None = None ) -> None: dist_info = f"{name}-{version}.dist-info" files = files or [] with zipfile.ZipFile(path) as z: namelist = z.namelist() - # we use concatenation here for PY2 compat for filename in ["WHEEL", "METADATA", "RECORD", *files]: assert f"{dist_info}/{filename}" in namelist def validate_sdist_contents( - name: str, version: str, path: str, files: list[str] + name: str, version: str, path: Path, files: list[str] ) -> None: escaped_name = name.replace("-", "_") with tarfile.open(path) as tar: diff --git a/tests/utils/test_helpers.py b/tests/utils/test_helpers.py index ea8b03d48..fbdde65ce 100644 --- a/tests/utils/test_helpers.py +++ b/tests/utils/test_helpers.py @@ -1,6 +1,5 @@ from __future__ import annotations -import os import sys import tempfile @@ -102,13 +101,13 @@ def test_utils_helpers_combine_unicode() -> None: def test_utils_helpers_temporary_directory_readonly_file() -> None: with temporary_directory() as temp_dir: - readonly_filename = os.path.join(temp_dir, "file.txt") - with open(readonly_filename, "w+", encoding="utf-8") as readonly_file: + readonly_filename = temp_dir / "file.txt" + with readonly_filename.open(mode="w+", encoding="utf-8") as readonly_file: readonly_file.write("Poetry rocks!") - os.chmod(str(readonly_filename), S_IREAD) + readonly_filename.chmod(S_IREAD) - assert not os.path.exists(temp_dir) - assert not os.path.exists(readonly_filename) + assert not temp_dir.exists() + assert not readonly_filename.exists() @pytest.mark.parametrize( @@ -133,9 +132,11 @@ def test_temporary_directory_python_3_10_or_newer(mocker: MockerFixture) -> None mocked_temp_dir = mocker.patch("tempfile.TemporaryDirectory") mocked_mkdtemp = mocker.patch("tempfile.mkdtemp") + mocked_temp_dir.return_value.__enter__.return_value = "hello from test" + mocker.patch.object(sys, "version_info", (3, 10)) with temporary_directory() as tmp: - assert tmp + assert tmp == Path("hello from test") assert not mocked_rmtree.called assert not mocked_mkdtemp.called @@ -151,7 +152,7 @@ def test_temporary_directory_python_3_9_or_older(mocker: MockerFixture) -> None: mocker.patch.object(sys, "version_info", (3, 9)) with temporary_directory() as tmp: - assert tmp == "hello from test" + assert tmp == Path("hello from test") assert mocked_rmtree.called assert mocked_mkdtemp.called diff --git a/tests/vcs/test_vcs.py b/tests/vcs/test_vcs.py index abd72e5fb..b03c86e06 100644 --- a/tests/vcs/test_vcs.py +++ b/tests/vcs/test_vcs.py @@ -530,8 +530,7 @@ def test_get_vcs_ignored_subdir(tmp_path: Path) -> None: repo_path.mkdir() assert repo_path.exists() assert subprocess.check_call([executable(), "init"], cwd=repo_path) == 0 - with open(repo_path / ".gitignore", "w", encoding="utf-8") as f: - f.write("/ignored") + (repo_path / ".gitignore").write_text("/ignored", encoding="utf-8") subdir = repo_path / "ignored" subdir.mkdir()