14
14
from _pytest .compat import final
15
15
from _pytest .compat import LEGACY_PATH
16
16
from _pytest .compat import legacy_path
17
+ from _pytest .config import PytestPluginManager
17
18
from _pytest .deprecated import check_ispytest
19
+ from _pytest .main import Session
20
+ from _pytest .monkeypatch import MonkeyPatch
21
+ from _pytest .nodes import Collector
22
+ from _pytest .nodes import Item
18
23
from _pytest .nodes import Node
24
+ from _pytest .pytester import HookRecorder
25
+ from _pytest .pytester import Pytester
26
+ from _pytest .pytester import RunResult
19
27
from _pytest .terminal import TerminalReporter
28
+ from _pytest .tmpdir import TempPathFactory
20
29
21
30
if TYPE_CHECKING :
22
31
from typing_extensions import Final
@@ -35,10 +44,10 @@ class Testdir:
35
44
36
45
__test__ = False
37
46
38
- CLOSE_STDIN : "Final" = pytest . Pytester .CLOSE_STDIN
39
- TimeoutExpired : "Final" = pytest . Pytester .TimeoutExpired
47
+ CLOSE_STDIN : "Final" = Pytester .CLOSE_STDIN
48
+ TimeoutExpired : "Final" = Pytester .TimeoutExpired
40
49
41
- def __init__ (self , pytester : pytest . Pytester , * , _ispytest : bool = False ) -> None :
50
+ def __init__ (self , pytester : Pytester , * , _ispytest : bool = False ) -> None :
42
51
check_ispytest (_ispytest )
43
52
self ._pytester = pytester
44
53
@@ -64,10 +73,10 @@ def plugins(self, plugins):
64
73
self ._pytester .plugins = plugins
65
74
66
75
@property
67
- def monkeypatch (self ) -> pytest . MonkeyPatch :
76
+ def monkeypatch (self ) -> MonkeyPatch :
68
77
return self ._pytester ._monkeypatch
69
78
70
- def make_hook_recorder (self , pluginmanager ) -> pytest . HookRecorder :
79
+ def make_hook_recorder (self , pluginmanager ) -> HookRecorder :
71
80
"""See :meth:`Pytester.make_hook_recorder`."""
72
81
return self ._pytester .make_hook_recorder (pluginmanager )
73
82
@@ -131,19 +140,15 @@ def copy_example(self, name=None) -> LEGACY_PATH:
131
140
"""See :meth:`Pytester.copy_example`."""
132
141
return legacy_path (self ._pytester .copy_example (name ))
133
142
134
- def getnode (
135
- self , config : pytest .Config , arg
136
- ) -> Optional [Union [pytest .Item , pytest .Collector ]]:
143
+ def getnode (self , config : pytest .Config , arg ) -> Optional [Union [Item , Collector ]]:
137
144
"""See :meth:`Pytester.getnode`."""
138
145
return self ._pytester .getnode (config , arg )
139
146
140
147
def getpathnode (self , path ):
141
148
"""See :meth:`Pytester.getpathnode`."""
142
149
return self ._pytester .getpathnode (path )
143
150
144
- def genitems (
145
- self , colitems : List [Union [pytest .Item , pytest .Collector ]]
146
- ) -> List [pytest .Item ]:
151
+ def genitems (self , colitems : List [Union [Item , Collector ]]) -> List [Item ]:
147
152
"""See :meth:`Pytester.genitems`."""
148
153
return self ._pytester .genitems (colitems )
149
154
@@ -165,11 +170,11 @@ def inline_run(self, *args, plugins=(), no_reraise_ctrlc: bool = False):
165
170
* args , plugins = plugins , no_reraise_ctrlc = no_reraise_ctrlc
166
171
)
167
172
168
- def runpytest_inprocess (self , * args , ** kwargs ) -> pytest . RunResult :
173
+ def runpytest_inprocess (self , * args , ** kwargs ) -> RunResult :
169
174
"""See :meth:`Pytester.runpytest_inprocess`."""
170
175
return self ._pytester .runpytest_inprocess (* args , ** kwargs )
171
176
172
- def runpytest (self , * args , ** kwargs ) -> pytest . RunResult :
177
+ def runpytest (self , * args , ** kwargs ) -> RunResult :
173
178
"""See :meth:`Pytester.runpytest`."""
174
179
return self ._pytester .runpytest (* args , ** kwargs )
175
180
@@ -196,8 +201,8 @@ def getmodulecol(self, source, configargs=(), withinit=False):
196
201
)
197
202
198
203
def collect_by_name (
199
- self , modcol : pytest . Collector , name : str
200
- ) -> Optional [Union [pytest . Item , pytest . Collector ]]:
204
+ self , modcol : Collector , name : str
205
+ ) -> Optional [Union [Item , Collector ]]:
201
206
"""See :meth:`Pytester.collect_by_name`."""
202
207
return self ._pytester .collect_by_name (modcol , name )
203
208
@@ -212,19 +217,19 @@ def popen(
212
217
"""See :meth:`Pytester.popen`."""
213
218
return self ._pytester .popen (cmdargs , stdout , stderr , stdin , ** kw )
214
219
215
- def run (self , * cmdargs , timeout = None , stdin = CLOSE_STDIN ) -> pytest . RunResult :
220
+ def run (self , * cmdargs , timeout = None , stdin = CLOSE_STDIN ) -> RunResult :
216
221
"""See :meth:`Pytester.run`."""
217
222
return self ._pytester .run (* cmdargs , timeout = timeout , stdin = stdin )
218
223
219
- def runpython (self , script ) -> pytest . RunResult :
224
+ def runpython (self , script ) -> RunResult :
220
225
"""See :meth:`Pytester.runpython`."""
221
226
return self ._pytester .runpython (script )
222
227
223
228
def runpython_c (self , command ):
224
229
"""See :meth:`Pytester.runpython_c`."""
225
230
return self ._pytester .runpython_c (command )
226
231
227
- def runpytest_subprocess (self , * args , timeout = None ) -> pytest . RunResult :
232
+ def runpytest_subprocess (self , * args , timeout = None ) -> RunResult :
228
233
"""See :meth:`Pytester.runpytest_subprocess`."""
229
234
return self ._pytester .runpytest_subprocess (* args , timeout = timeout )
230
235
@@ -245,13 +250,10 @@ def __str__(self) -> str:
245
250
return str (self .tmpdir )
246
251
247
252
248
- pytest .Testdir = Testdir # type: ignore[attr-defined]
249
-
250
-
251
253
class LegacyTestdirPlugin :
252
254
@staticmethod
253
255
@pytest .fixture
254
- def testdir (pytester : pytest . Pytester ) -> Testdir :
256
+ def testdir (pytester : Pytester ) -> Testdir :
255
257
"""
256
258
Identical to :fixture:`pytester`, and provides an instance whose methods return
257
259
legacy ``LEGACY_PATH`` objects instead when applicable.
@@ -267,10 +269,10 @@ class TempdirFactory:
267
269
"""Backward compatibility wrapper that implements :class:``_pytest.compat.LEGACY_PATH``
268
270
for :class:``TempPathFactory``."""
269
271
270
- _tmppath_factory : pytest . TempPathFactory
272
+ _tmppath_factory : TempPathFactory
271
273
272
274
def __init__ (
273
- self , tmppath_factory : pytest . TempPathFactory , * , _ispytest : bool = False
275
+ self , tmppath_factory : TempPathFactory , * , _ispytest : bool = False
274
276
) -> None :
275
277
check_ispytest (_ispytest )
276
278
self ._tmppath_factory = tmppath_factory
@@ -284,9 +286,6 @@ def getbasetemp(self) -> LEGACY_PATH:
284
286
return legacy_path (self ._tmppath_factory .getbasetemp ().resolve ())
285
287
286
288
287
- pytest .TempdirFactory = TempdirFactory # type: ignore[attr-defined]
288
-
289
-
290
289
class LegacyTmpdirPlugin :
291
290
@staticmethod
292
291
@pytest .fixture (scope = "session" )
@@ -368,7 +367,7 @@ def Config_inifile(self: pytest.Config) -> Optional[LEGACY_PATH]:
368
367
return legacy_path (str (self .inipath )) if self .inipath else None
369
368
370
369
371
- def Session_stardir (self : pytest . Session ) -> LEGACY_PATH :
370
+ def Session_stardir (self : Session ) -> LEGACY_PATH :
372
371
"""The path from which pytest was invoked.
373
372
374
373
Prefer to use ``startpath`` which is a :class:`pathlib.Path`.
@@ -453,9 +452,7 @@ def pytest_configure(config: pytest.Config) -> None:
453
452
454
453
455
454
@pytest .hookimpl
456
- def pytest_plugin_registered (
457
- plugin : object , manager : pytest .PytestPluginManager
458
- ) -> None :
455
+ def pytest_plugin_registered (plugin : object , manager : PytestPluginManager ) -> None :
459
456
# pytester is not loaded by default and is commonly loaded from a conftest,
460
457
# so checking for it in `pytest_configure` is not enough.
461
458
is_pytester = plugin is manager .get_plugin ("pytester" )
0 commit comments