Skip to content

Commit b43ab38

Browse files
committed
subtests: remove direct pytest import
1 parent d126214 commit b43ab38

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/_pytest/subtests.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,27 @@
2121
from _pytest.capture import CaptureFixture
2222
from _pytest.capture import FDCapture
2323
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
2428
from _pytest.fixtures import SubRequest
2529
from _pytest.logging import catching_logs
2630
from _pytest.logging import LogCaptureHandler
31+
from _pytest.nodes import Item
2732
from _pytest.reports import TestReport
2833
from _pytest.runner import CallInfo
2934
from _pytest.runner import check_interactive_exception
3035
from _pytest.unittest import TestCaseFunction
31-
import pytest
36+
from _pytest.warning_types import PytestDeprecationWarning
3237

3338

3439
if TYPE_CHECKING:
3540
from types import TracebackType
3641
from typing import Literal
3742

3843

39-
def pytest_addoption(parser: pytest.Parser) -> None:
44+
def pytest_addoption(parser: Parser) -> None:
4045
group = parser.getgroup("subtests")
4146
group.addoption(
4247
"--no-subtests-shortletter",
@@ -174,7 +179,7 @@ def _addSubTest(
174179
self._originaladdSkip(testcase, reason) # type: ignore[attr-defined]
175180

176181

177-
def pytest_configure(config: pytest.Config) -> None:
182+
def pytest_configure(config: Config) -> None:
178183
TestCaseFunction.addSubTest = _addSubTest # type: ignore[attr-defined]
179184
TestCaseFunction.failfast = False # type: ignore[attr-defined]
180185
# This condition is to prevent `TestCaseFunction._originaladdSkip` being assigned again in a subprocess from a
@@ -217,7 +222,7 @@ def pytest_unconfigure() -> None:
217222
del TestCaseFunction._originaladdSkip
218223

219224

220-
@pytest.fixture
225+
@fixture
221226
def subtests(request: SubRequest) -> Generator[SubTests, None, None]:
222227
"""Provides subtests functionality."""
223228
capmam = request.node.config.pluginmanager.get_plugin("capturemanager")
@@ -235,7 +240,7 @@ class SubTests:
235240
request: SubRequest = attr.ib()
236241

237242
@property
238-
def item(self) -> pytest.Item:
243+
def item(self) -> Item:
239244
return self.request.node
240245

241246
def test(
@@ -414,7 +419,7 @@ def ignore_pytest_private_warning() -> Generator[None, None, None]:
414419
warnings.filterwarnings(
415420
"ignore",
416421
"A private pytest class or function was used.",
417-
category=pytest.PytestDeprecationWarning,
422+
category=PytestDeprecationWarning,
418423
)
419424
yield
420425

@@ -424,7 +429,7 @@ class Captured:
424429
out = attr.ib(default="", type=str)
425430
err = attr.ib(default="", type=str)
426431

427-
def update_report(self, report: pytest.TestReport) -> None:
432+
def update_report(self, report: TestReport) -> None:
428433
if self.out:
429434
report.sections.append(("Captured stdout call", self.out))
430435
if self.err:
@@ -435,16 +440,16 @@ class CapturedLogs:
435440
def __init__(self, handler: LogCaptureHandler) -> None:
436441
self._handler = handler
437442

438-
def update_report(self, report: pytest.TestReport) -> None:
443+
def update_report(self, report: TestReport) -> None:
439444
report.sections.append(("Captured log call", self._handler.stream.getvalue()))
440445

441446

442447
class NullCapturedLogs:
443-
def update_report(self, report: pytest.TestReport) -> None:
448+
def update_report(self, report: TestReport) -> None:
444449
pass
445450

446451

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:
448453
if isinstance(report, SubTestReport):
449454
return report._to_json()
450455
return None
@@ -456,10 +461,10 @@ def pytest_report_from_serializable(data: dict[str, Any]) -> SubTestReport | Non
456461
return None
457462

458463

459-
@pytest.hookimpl(tryfirst=True)
464+
@hookimpl(tryfirst=True)
460465
def pytest_report_teststatus(
461-
report: pytest.TestReport,
462-
config: pytest.Config,
466+
report: TestReport,
467+
config: Config,
463468
) -> tuple[str, str, str | Mapping[str, bool]] | None:
464469
if report.when != "call" or not isinstance(report, SubTestReport):
465470
return None

0 commit comments

Comments
 (0)