21
21
from _pytest .capture import CaptureFixture
22
22
from _pytest .capture import FDCapture
23
23
from _pytest .capture import SysCapture
24
+ from _pytest .config import Config
25
+ from _pytest .config import hookimpl
26
+ from _pytest .config import Parser
27
+ from _pytest .fixtures import fixture
24
28
from _pytest .fixtures import SubRequest
25
29
from _pytest .logging import catching_logs
26
30
from _pytest .logging import LogCaptureHandler
31
+ from _pytest .nodes import Item
27
32
from _pytest .reports import TestReport
28
33
from _pytest .runner import CallInfo
29
34
from _pytest .runner import check_interactive_exception
30
35
from _pytest .unittest import TestCaseFunction
31
- import pytest
36
+ from _pytest . warning_types import PytestDeprecationWarning
32
37
33
38
34
39
if TYPE_CHECKING :
35
40
from types import TracebackType
36
41
from typing import Literal
37
42
38
43
39
- def pytest_addoption (parser : pytest . Parser ) -> None :
44
+ def pytest_addoption (parser : Parser ) -> None :
40
45
group = parser .getgroup ("subtests" )
41
46
group .addoption (
42
47
"--no-subtests-shortletter" ,
@@ -174,7 +179,7 @@ def _addSubTest(
174
179
self ._originaladdSkip (testcase , reason ) # type: ignore[attr-defined]
175
180
176
181
177
- def pytest_configure (config : pytest . Config ) -> None :
182
+ def pytest_configure (config : Config ) -> None :
178
183
TestCaseFunction .addSubTest = _addSubTest # type: ignore[attr-defined]
179
184
TestCaseFunction .failfast = False # type: ignore[attr-defined]
180
185
# This condition is to prevent `TestCaseFunction._originaladdSkip` being assigned again in a subprocess from a
@@ -217,7 +222,7 @@ def pytest_unconfigure() -> None:
217
222
del TestCaseFunction ._originaladdSkip
218
223
219
224
220
- @pytest . fixture
225
+ @fixture
221
226
def subtests (request : SubRequest ) -> Generator [SubTests , None , None ]:
222
227
"""Provides subtests functionality."""
223
228
capmam = request .node .config .pluginmanager .get_plugin ("capturemanager" )
@@ -235,7 +240,7 @@ class SubTests:
235
240
request : SubRequest = attr .ib ()
236
241
237
242
@property
238
- def item (self ) -> pytest . Item :
243
+ def item (self ) -> Item :
239
244
return self .request .node
240
245
241
246
def test (
@@ -414,7 +419,7 @@ def ignore_pytest_private_warning() -> Generator[None, None, None]:
414
419
warnings .filterwarnings (
415
420
"ignore" ,
416
421
"A private pytest class or function was used." ,
417
- category = pytest . PytestDeprecationWarning ,
422
+ category = PytestDeprecationWarning ,
418
423
)
419
424
yield
420
425
@@ -424,7 +429,7 @@ class Captured:
424
429
out = attr .ib (default = "" , type = str )
425
430
err = attr .ib (default = "" , type = str )
426
431
427
- def update_report (self , report : pytest . TestReport ) -> None :
432
+ def update_report (self , report : TestReport ) -> None :
428
433
if self .out :
429
434
report .sections .append (("Captured stdout call" , self .out ))
430
435
if self .err :
@@ -435,16 +440,16 @@ class CapturedLogs:
435
440
def __init__ (self , handler : LogCaptureHandler ) -> None :
436
441
self ._handler = handler
437
442
438
- def update_report (self , report : pytest . TestReport ) -> None :
443
+ def update_report (self , report : TestReport ) -> None :
439
444
report .sections .append (("Captured log call" , self ._handler .stream .getvalue ()))
440
445
441
446
442
447
class NullCapturedLogs :
443
- def update_report (self , report : pytest . TestReport ) -> None :
448
+ def update_report (self , report : TestReport ) -> None :
444
449
pass
445
450
446
451
447
- def pytest_report_to_serializable (report : pytest . TestReport ) -> dict [str , Any ] | None :
452
+ def pytest_report_to_serializable (report : TestReport ) -> dict [str , Any ] | None :
448
453
if isinstance (report , SubTestReport ):
449
454
return report ._to_json ()
450
455
return None
@@ -456,10 +461,10 @@ def pytest_report_from_serializable(data: dict[str, Any]) -> SubTestReport | Non
456
461
return None
457
462
458
463
459
- @pytest . hookimpl (tryfirst = True )
464
+ @hookimpl (tryfirst = True )
460
465
def pytest_report_teststatus (
461
- report : pytest . TestReport ,
462
- config : pytest . Config ,
466
+ report : TestReport ,
467
+ config : Config ,
463
468
) -> tuple [str , str , str | Mapping [str , bool ]] | None :
464
469
if report .when != "call" or not isinstance (report , SubTestReport ):
465
470
return None
0 commit comments