Skip to content

Commit f6db7ae

Browse files
committed
Let mkdir() and mkpydir() receive PathLike names
These pytester utility methods were annotated to only receive `str` names, but they naturally support os.PathLike values, as well. This makes writing some pytester calls a little nicer, such as when creating a directory based on a `.joinpath()` call. We previously needed to cast that intermediate value to a `str`.
1 parent eb8b3ad commit f6db7ae

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/_pytest/pytester.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,13 +904,13 @@ def syspathinsert(
904904

905905
self._monkeypatch.syspath_prepend(str(path))
906906

907-
def mkdir(self, name: str) -> Path:
907+
def mkdir(self, name: Union[str, "os.PathLike[str]"]) -> Path:
908908
"""Create a new (sub)directory."""
909909
p = self.path / name
910910
p.mkdir()
911911
return p
912912

913-
def mkpydir(self, name: str) -> Path:
913+
def mkpydir(self, name: Union[str, "os.PathLike[str]"]) -> Path:
914914
"""Create a new python package.
915915
916916
This creates a (sub)directory with an empty ``__init__.py`` file so it

0 commit comments

Comments
 (0)