58
58
59
59
import pexpect
60
60
61
+ PathLike = os .PathLike [str ]
62
+ else :
63
+ PathLike = os .PathLike
64
+
61
65
62
66
IGNORE_PAM = [ # filenames added when obtaining details about the current user
63
67
"/var/lib/sss/mc/passwd"
@@ -434,22 +438,22 @@ def LineMatcher_fixture(request: FixtureRequest) -> Type["LineMatcher"]:
434
438
435
439
436
440
@pytest .fixture
437
- def pytester (request : FixtureRequest , tmp_path_factory : TempPathFactory ) -> "PyTester " :
441
+ def pytester (request : FixtureRequest , tmp_path_factory : TempPathFactory ) -> "Pytester " :
438
442
"""
439
443
Facilities to write tests/configuration files, execute pytest in isolation, and match
440
444
against expected output, perfect for black-box testing of pytest plugins.
441
445
442
446
It attempts to isolate the test run from external factors as much as possible, modifying
443
447
the current working directory to ``path`` and environment variables during initialization.
444
448
445
- It attempts to isolate the test run from external factors as much as possible, modifying
446
- the current working directory to ``tmp_path`` and environment variables during initialization .
449
+ It is particularly useful for testing plugins. It is similar to the :fixture:`tmp_path`
450
+ fixture but provides methods which aid in testing pytest itself .
447
451
"""
448
- return PyTester (request , tmp_path_factory )
452
+ return Pytester (request , tmp_path_factory )
449
453
450
454
451
455
@pytest .fixture
452
- def testdir (pytester : "PyTester " ) -> "Testdir" :
456
+ def testdir (pytester : "Pytester " ) -> "Testdir" :
453
457
"""
454
458
Identical to :fixture:`test_path`, and provides an instance whose methods return
455
459
legacy ``py.path.local`` objects instead when applicable.
@@ -619,7 +623,7 @@ def restore(self) -> None:
619
623
620
624
621
625
@final
622
- class PyTester :
626
+ class Pytester :
623
627
"""
624
628
Facilities to write tests/configuration files, execute pytest in isolation, and match
625
629
against expected output, perfect for black-box testing of pytest plugins.
@@ -685,7 +689,7 @@ def path(self) -> Path:
685
689
return self ._path
686
690
687
691
def __repr__ (self ) -> str :
688
- return f"<PyTester { self .path !r} >"
692
+ return f"<Pytester { self .path !r} >"
689
693
690
694
def _finalize (self ) -> None :
691
695
"""
@@ -888,9 +892,7 @@ def copy_example(self, name=None) -> Path:
888
892
example_path = maybe_file
889
893
else :
890
894
raise LookupError (
891
- "{} cant be found as module or package in {}" .format (
892
- func_name , example_dir .bestrelpath (self ._request .config .rootdir )
893
- )
895
+ f"{ func_name } cant be found as module or package in { example_dir } "
894
896
)
895
897
else :
896
898
example_path = example_dir .joinpath (name )
@@ -912,7 +914,9 @@ def copy_example(self, name=None) -> Path:
912
914
913
915
Session = Session
914
916
915
- def getnode (self , config : Config , arg ) -> Optional [Union [Collector , Item ]]:
917
+ def getnode (
918
+ self , config : Config , arg : Union [PathLike , str ]
919
+ ) -> Optional [Union [Collector , Item ]]:
916
920
"""Return the collection node of a file.
917
921
918
922
:param _pytest.config.Config config:
@@ -929,14 +933,15 @@ def getnode(self, config: Config, arg) -> Optional[Union[Collector, Item]]:
929
933
config .hook .pytest_sessionfinish (session = session , exitstatus = ExitCode .OK )
930
934
return res
931
935
932
- def getpathnode (self , path ):
936
+ def getpathnode (self , path : Union [ PathLike , str ] ):
933
937
"""Return the collection node of a file.
934
938
935
939
This is like :py:meth:`getnode` but uses :py:meth:`parseconfigure` to
936
940
create the (configured) pytest Config instance.
937
941
938
942
:param py.path.local path: Path to the file.
939
943
"""
944
+ path = py .path .local (path )
940
945
config = self .parseconfigure (path )
941
946
session = Session .from_config (config )
942
947
x = session .fspath .bestrelpath (path )
@@ -1279,7 +1284,7 @@ def popen(
1279
1284
1280
1285
def run (
1281
1286
self ,
1282
- * cmdargs : Union [str , py . path . local , Path ],
1287
+ * cmdargs : Union [str , PathLike ],
1283
1288
timeout : Optional [float ] = None ,
1284
1289
stdin = CLOSE_STDIN ,
1285
1290
) -> RunResult :
@@ -1290,10 +1295,10 @@ def run(
1290
1295
:param cmdargs:
1291
1296
The sequence of arguments to pass to `subprocess.Popen()`, with ``Path``
1292
1297
and ``py.path.local`` objects being converted to ``str`` automatically.
1293
- :kwarg timeout:
1298
+ :param timeout:
1294
1299
The period in seconds after which to timeout and raise
1295
1300
:py:class:`Testdir.TimeoutExpired`
1296
- :kwarg stdin:
1301
+ :param stdin:
1297
1302
Optional standard input. Bytes are being send, closing
1298
1303
the pipe, otherwise it is passed through to ``popen``.
1299
1304
Defaults to ``CLOSE_STDIN``, which translates to using a pipe
@@ -1461,19 +1466,19 @@ def assert_contains_lines(self, lines2: Sequence[str]) -> None:
1461
1466
@attr .s (repr = False , str = False )
1462
1467
class Testdir :
1463
1468
"""
1464
- Similar to :class:`PyTester `, but this class works with legacy py.path.local objects instead.
1469
+ Similar to :class:`Pytester `, but this class works with legacy py.path.local objects instead.
1465
1470
1466
- All methods just forward to an internal :class:`PyTester ` instance, converting results
1471
+ All methods just forward to an internal :class:`Pytester ` instance, converting results
1467
1472
to `py.path.local` objects as necessary.
1468
1473
"""
1469
1474
1470
1475
__test__ = False
1471
1476
1472
- CLOSE_STDIN = PyTester .CLOSE_STDIN
1473
- TimeoutExpired = PyTester .TimeoutExpired
1474
- Session = PyTester .Session
1477
+ CLOSE_STDIN = Pytester .CLOSE_STDIN
1478
+ TimeoutExpired = Pytester .TimeoutExpired
1479
+ Session = Pytester .Session
1475
1480
1476
- _pytester = attr .ib (type = PyTester )
1481
+ _pytester = attr .ib (type = Pytester )
1477
1482
1478
1483
@property
1479
1484
def tmpdir (self ) -> py .path .local :
0 commit comments