20
20
from typing import Callable
21
21
from typing import Dict
22
22
from typing import Generator
23
+ from typing import IO
23
24
from typing import Iterable
24
25
from typing import List
25
26
from typing import Optional
41
42
from _pytest ._code import Source
42
43
from _pytest .capture import _get_multicapture
43
44
from _pytest .compat import final
45
+ from _pytest .compat import NOTSET
46
+ from _pytest .compat import NotSetType
44
47
from _pytest .config import _PluggyPlugin
45
48
from _pytest .config import Config
46
49
from _pytest .config import ExitCode
66
69
67
70
68
71
if TYPE_CHECKING :
72
+ from typing_extensions import Final
69
73
from typing_extensions import Literal
70
74
71
75
import pexpect
@@ -651,7 +655,7 @@ class Pytester:
651
655
652
656
__test__ = False
653
657
654
- CLOSE_STDIN = object
658
+ CLOSE_STDIN : "Final" = NOTSET
655
659
656
660
class TimeoutExpired (Exception ):
657
661
pass
@@ -1297,13 +1301,13 @@ def popen(
1297
1301
cmdargs : Sequence [Union [str , "os.PathLike[str]" ]],
1298
1302
stdout : Union [int , TextIO ] = subprocess .PIPE ,
1299
1303
stderr : Union [int , TextIO ] = subprocess .PIPE ,
1300
- stdin = CLOSE_STDIN ,
1304
+ stdin : Union [ NotSetType , bytes , IO [ Any ], int ] = CLOSE_STDIN ,
1301
1305
** kw ,
1302
1306
):
1303
1307
"""Invoke :py:class:`subprocess.Popen`.
1304
1308
1305
1309
Calls :py:class:`subprocess.Popen` making sure the current working
1306
- directory is in the ``PYTHONPATH``.
1310
+ directory is in ``PYTHONPATH``.
1307
1311
1308
1312
You probably want to use :py:meth:`run` instead.
1309
1313
"""
@@ -1334,7 +1338,7 @@ def run(
1334
1338
self ,
1335
1339
* cmdargs : Union [str , "os.PathLike[str]" ],
1336
1340
timeout : Optional [float ] = None ,
1337
- stdin = CLOSE_STDIN ,
1341
+ stdin : Union [ NotSetType , bytes , IO [ Any ], int ] = CLOSE_STDIN ,
1338
1342
) -> RunResult :
1339
1343
"""Run a command with arguments.
1340
1344
@@ -1426,21 +1430,17 @@ def _dump_lines(self, lines, fp):
1426
1430
def _getpytestargs (self ) -> Tuple [str , ...]:
1427
1431
return sys .executable , "-mpytest"
1428
1432
1429
- def runpython (self , script ) -> RunResult :
1430
- """Run a python script using sys.executable as interpreter.
1431
-
1432
- :rtype: RunResult
1433
- """
1433
+ def runpython (self , script : "os.PathLike[str]" ) -> RunResult :
1434
+ """Run a python script using sys.executable as interpreter."""
1434
1435
return self .run (sys .executable , script )
1435
1436
1436
- def runpython_c (self , command ):
1437
- """Run python -c "command".
1438
-
1439
- :rtype: RunResult
1440
- """
1437
+ def runpython_c (self , command : str ) -> RunResult :
1438
+ """Run ``python -c "command"``."""
1441
1439
return self .run (sys .executable , "-c" , command )
1442
1440
1443
- def runpytest_subprocess (self , * args , timeout : Optional [float ] = None ) -> RunResult :
1441
+ def runpytest_subprocess (
1442
+ self , * args : Union [str , "os.PathLike[str]" ], timeout : Optional [float ] = None
1443
+ ) -> RunResult :
1444
1444
"""Run pytest as a subprocess with given arguments.
1445
1445
1446
1446
Any plugins added to the :py:attr:`plugins` list will be added using the
@@ -1454,8 +1454,6 @@ def runpytest_subprocess(self, *args, timeout: Optional[float] = None) -> RunRes
1454
1454
:param timeout:
1455
1455
The period in seconds after which to timeout and raise
1456
1456
:py:class:`Pytester.TimeoutExpired`.
1457
-
1458
- :rtype: RunResult
1459
1457
"""
1460
1458
__tracebackhide__ = True
1461
1459
p = make_numbered_dir (root = self .path , prefix = "runpytest-" )
@@ -1529,9 +1527,9 @@ class Testdir:
1529
1527
1530
1528
__test__ = False
1531
1529
1532
- CLOSE_STDIN = Pytester .CLOSE_STDIN
1533
- TimeoutExpired = Pytester .TimeoutExpired
1534
- Session = Pytester .Session
1530
+ CLOSE_STDIN : "Final" = Pytester .CLOSE_STDIN
1531
+ TimeoutExpired : "Final" = Pytester .TimeoutExpired
1532
+ Session : "Final" = Pytester .Session
1535
1533
1536
1534
def __init__ (self , pytester : Pytester , * , _ispytest : bool = False ) -> None :
1537
1535
check_ispytest (_ispytest )
@@ -1695,8 +1693,8 @@ def collect_by_name(
1695
1693
def popen (
1696
1694
self ,
1697
1695
cmdargs ,
1698
- stdout : Union [ int , TextIO ] = subprocess .PIPE ,
1699
- stderr : Union [ int , TextIO ] = subprocess .PIPE ,
1696
+ stdout = subprocess .PIPE ,
1697
+ stderr = subprocess .PIPE ,
1700
1698
stdin = CLOSE_STDIN ,
1701
1699
** kw ,
1702
1700
):
0 commit comments