Skip to content

Commit ad65e81

Browse files
authored
Merge pull request #8111 from antonblr/testdir-to-pytester-python
tests: Migrate testing/python to pytester fixture
2 parents 7e2e663 + 4ed9a38 commit ad65e81

File tree

7 files changed

+1251
-1132
lines changed

7 files changed

+1251
-1132
lines changed

src/_pytest/pytester.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,9 @@ def parseconfigure(self, *args: Union[str, "os.PathLike[str]"]) -> Config:
11901190
config._do_configure()
11911191
return config
11921192

1193-
def getitem(self, source: str, funcname: str = "test_func") -> Item:
1193+
def getitem(
1194+
self, source: Union[str, "os.PathLike[str]"], funcname: str = "test_func"
1195+
) -> Item:
11941196
"""Return the test item for a test function.
11951197
11961198
Writes the source to a python file and runs pytest's collection on
@@ -1210,7 +1212,7 @@ def getitem(self, source: str, funcname: str = "test_func") -> Item:
12101212
funcname, source, items
12111213
)
12121214

1213-
def getitems(self, source: str) -> List[Item]:
1215+
def getitems(self, source: Union[str, "os.PathLike[str]"]) -> List[Item]:
12141216
"""Return all test items collected from the module.
12151217
12161218
Writes the source to a Python file and runs pytest's collection on
@@ -1220,7 +1222,11 @@ def getitems(self, source: str) -> List[Item]:
12201222
return self.genitems([modcol])
12211223

12221224
def getmodulecol(
1223-
self, source: Union[str, Path], configargs=(), *, withinit: bool = False
1225+
self,
1226+
source: Union[str, "os.PathLike[str]"],
1227+
configargs=(),
1228+
*,
1229+
withinit: bool = False,
12241230
):
12251231
"""Return the module collection node for ``source``.
12261232
@@ -1238,7 +1244,9 @@ def getmodulecol(
12381244
Whether to also write an ``__init__.py`` file to the same
12391245
directory to ensure it is a package.
12401246
"""
1241-
if isinstance(source, Path):
1247+
# TODO: Remove type ignore in next mypy release (> 0.790).
1248+
# https://github.com/python/typeshed/pull/4582
1249+
if isinstance(source, os.PathLike): # type: ignore[misc]
12421250
path = self.path.joinpath(source)
12431251
assert not withinit, "not supported for paths"
12441252
else:

0 commit comments

Comments
 (0)