From f6db7ae74900e0dbf39553ebd531b23c31d07db0 Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Mon, 25 Apr 2022 17:18:33 -0700 Subject: [PATCH] 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`. --- src/_pytest/pytester.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 359e2aebd..4493bdb80 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -904,13 +904,13 @@ class Pytester: self._monkeypatch.syspath_prepend(str(path)) - def mkdir(self, name: str) -> Path: + def mkdir(self, name: Union[str, "os.PathLike[str]"]) -> Path: """Create a new (sub)directory.""" p = self.path / name p.mkdir() return p - def mkpydir(self, name: str) -> Path: + def mkpydir(self, name: Union[str, "os.PathLike[str]"]) -> Path: """Create a new python package. This creates a (sub)directory with an empty ``__init__.py`` file so it