Skip to content

Commit 3683599

Browse files
committed
Force using xdist plugin and fix linting
1 parent ee3eaeb commit 3683599

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

src/_pytest/subtests.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
from collections.abc import Generator
55
from collections.abc import Iterator
66
from collections.abc import Mapping
7+
from contextlib import AbstractContextManager
78
from contextlib import contextmanager
89
from contextlib import ExitStack
910
from contextlib import nullcontext
1011
import sys
1112
import time
1213
from typing import Any
13-
from typing import ContextManager
1414
from typing import TYPE_CHECKING
1515
from unittest import TestCase
1616

@@ -23,12 +23,11 @@
2323
from _pytest.capture import SysCapture
2424
from _pytest.config import Config
2525
from _pytest.config import hookimpl
26-
from _pytest.config import Parser
26+
from _pytest.config.argparsing import Parser
2727
from _pytest.fixtures import fixture
2828
from _pytest.fixtures import SubRequest
2929
from _pytest.logging import catching_logs
3030
from _pytest.logging import LogCaptureHandler
31-
from _pytest.nodes import Item
3231
from _pytest.reports import TestReport
3332
from _pytest.runner import CallInfo
3433
from _pytest.runner import check_interactive_exception
@@ -85,7 +84,7 @@ def sub_test_description(self) -> str:
8584
parts.append(f"({params_desc})")
8685
return " ".join(parts) or "(<subtest>)"
8786

88-
def _to_json(self) -> dict:
87+
def _to_json(self) -> dict[str, Any]:
8988
data = super()._to_json()
9089
del data["context"]
9190
data["_report_type"] = "SubTestReport"
@@ -236,11 +235,11 @@ def subtests(request: SubRequest) -> Generator[SubTests, None, None]:
236235
@attr.s
237236
class SubTests:
238237
ihook: pluggy.HookRelay = attr.ib()
239-
suspend_capture_ctx: Callable[[], ContextManager] = attr.ib()
238+
suspend_capture_ctx: Callable[[], AbstractContextManager[None]] = attr.ib()
240239
request: SubRequest = attr.ib()
241240

242241
@property
243-
def item(self) -> Item:
242+
def item(self) -> Any:
244243
return self.request.node
245244

246245
def test(
@@ -282,7 +281,7 @@ class _SubTestContextManager:
282281
ihook: pluggy.HookRelay
283282
msg: str | None
284283
kwargs: dict[str, Any]
285-
suspend_capture_ctx: Callable[[], ContextManager]
284+
suspend_capture_ctx: Callable[[], AbstractContextManager[None]]
286285
request: SubRequest
287286

288287
def __enter__(self) -> None:
@@ -302,8 +301,8 @@ def __enter__(self) -> None:
302301

303302
def __exit__(
304303
self,
305-
exc_type: type[Exception] | None,
306-
exc_val: Exception | None,
304+
exc_type: type[BaseException] | None,
305+
exc_val: BaseException | None,
307306
exc_tb: TracebackType | None,
308307
) -> bool:
309308
__tracebackhide__ = True
@@ -352,7 +351,7 @@ def make_call_info(
352351
stop: float,
353352
duration: float,
354353
when: Literal["collect", "setup", "call", "teardown"],
355-
) -> CallInfo:
354+
) -> CallInfo[Any]:
356355
return CallInfo(
357356
None,
358357
exc_info,

testing/test_subtests.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
@pytest.mark.parametrize("mode", ["normal", "xdist"])
1414
class TestFixture:
15-
"""
16-
Tests for ``subtests`` fixture.
17-
"""
15+
"""Tests for ``subtests`` fixture."""
1816

1917
@pytest.fixture
2018
def simple_script(self, pytester: pytest.Pytester) -> None:
@@ -39,7 +37,7 @@ def test_simple_terminal_normal(
3937
else:
4038
assert mode == "xdist"
4139
pytest.importorskip("xdist")
42-
result = pytester.runpytest("-n1")
40+
result = pytester.runpytest("-n1", "-pxdist.plugin")
4341
expected_lines = ["1 worker [1 item]"]
4442

4543
expected_lines += [
@@ -69,7 +67,7 @@ def test_simple_terminal_verbose(
6967
else:
7068
assert mode == "xdist"
7169
pytest.importorskip("xdist")
72-
result = pytester.runpytest("-n1", "-v")
70+
result = pytester.runpytest("-n1", "-v", "-pxdist.plugin")
7371
expected_lines = [
7472
"1 worker [1 item]",
7573
"*gw0*100%* test_simple_terminal_verbose.py::test_foo*",
@@ -106,7 +104,7 @@ def test_foo(subtests):
106104
else:
107105
assert mode == "xdist"
108106
pytest.importorskip("xdist")
109-
result = pytester.runpytest("-n1")
107+
result = pytester.runpytest("-n1", "-pxdist.plugin")
110108
expected_lines = ["1 worker [1 item]"]
111109
expected_lines += ["* 1 passed, 3 skipped, 2 subtests passed in *"]
112110
result.stdout.fnmatch_lines(expected_lines)
@@ -130,7 +128,7 @@ def test_foo(subtests):
130128
else:
131129
assert mode == "xdist"
132130
pytest.importorskip("xdist")
133-
result = pytester.runpytest("-n1")
131+
result = pytester.runpytest("-n1", "-pxdist.plugin")
134132
expected_lines = ["1 worker [1 item]"]
135133
expected_lines += ["* 1 passed, 2 subtests passed, 3 subtests xfailed in *"]
136134
result.stdout.fnmatch_lines(expected_lines)
@@ -152,7 +150,7 @@ def test_typing_exported(subtests: SubTests) -> None:
152150
else:
153151
assert mode == "xdist"
154152
pytest.importorskip("xdist")
155-
result = pytester.runpytest("-n1")
153+
result = pytester.runpytest("-n1", "-pxdist.plugin")
156154
expected_lines = ["1 worker [1 item]"]
157155
expected_lines += ["* 1 passed *"]
158156
result.stdout.fnmatch_lines(expected_lines)
@@ -215,9 +213,7 @@ def test_foo(subtests):
215213

216214

217215
class TestSubTest:
218-
"""
219-
Test Test.subTest functionality.
220-
"""
216+
"""Test.subTest functionality."""
221217

222218
@pytest.fixture
223219
def simple_script(self, pytester: pytest.Pytester) -> Path:
@@ -264,11 +260,11 @@ def test_simple_terminal_normal(
264260
else:
265261
assert runner == "pytest-xdist"
266262
pytest.importorskip("xdist")
267-
result = pytester.runpytest(simple_script, "-n1")
263+
result = pytester.runpytest(simple_script, "-n1", "-pxdist.plugin")
268264
expected_lines = ["1 worker [1 item]"]
269265
result.stdout.fnmatch_lines(
270-
expected_lines
271-
+ [
266+
[
267+
*expected_lines,
272268
"* T.test_foo [[]custom[]] (i=1) *",
273269
"E * AssertionError: 1 != 0",
274270
"* T.test_foo [[]custom[]] (i=3) *",
@@ -310,16 +306,18 @@ def test_simple_terminal_verbose(
310306
else:
311307
assert runner == "pytest-xdist"
312308
pytest.importorskip("xdist")
313-
result = pytester.runpytest(simple_script, "-n1", "-v")
309+
result = pytester.runpytest(
310+
simple_script, "-n1", "-v", "-pxdist.plugin"
311+
)
314312
expected_lines = [
315313
"1 worker [1 item]",
316314
"*gw0*100%* SUBFAIL test_simple_terminal_verbose.py::T::test_foo*",
317315
"*gw0*100%* SUBFAIL test_simple_terminal_verbose.py::T::test_foo*",
318316
"*gw0*100%* PASSED test_simple_terminal_verbose.py::T::test_foo*",
319317
]
320318
result.stdout.fnmatch_lines(
321-
expected_lines
322-
+ [
319+
[
320+
*expected_lines,
323321
"* T.test_foo [[]custom[]] (i=1) *",
324322
"E * AssertionError: 1 != 0",
325323
"* T.test_foo [[]custom[]] (i=3) *",
@@ -470,15 +468,19 @@ def test_foo(self):
470468
result = pytester.runpytest(p, "-v", "-rsf")
471469
result.stdout.re_match_lines(
472470
[
473-
r"test_skip_with_failure.py::T::test_foo \[custom message\] \(i=0\) SUBSKIP \(skip subtest i=0\) .*",
474-
r"test_skip_with_failure.py::T::test_foo \[custom message\] \(i=3\) SUBSKIP \(skip subtest i=3\) .*",
471+
r"test_skip_with_failure.py::T::test_foo \[custom message\] \(i=0\) SUBSKIP"
472+
r" \(skip subtest i=0\) .*",
473+
r"test_skip_with_failure.py::T::test_foo \[custom message\] \(i=3\) SUBSKIP"
474+
r" \(skip subtest i=3\) .*",
475475
r"test_skip_with_failure.py::T::test_foo \[custom message\] \(i=4\) SUBFAIL .*",
476476
r"test_skip_with_failure.py::T::test_foo \[custom message\] \(i=9\) SUBFAIL .*",
477477
"test_skip_with_failure.py::T::test_foo PASSED .*",
478478
r"[custom message] (i=0) SUBSKIP [1] test_skip_with_failure.py:5: skip subtest i=0",
479479
r"[custom message] (i=0) SUBSKIP [1] test_skip_with_failure.py:5: skip subtest i=3",
480-
r"[custom message] (i=4) SUBFAIL test_skip_with_failure.py::T::test_foo - AssertionError: assert 4 < 4",
481-
r"[custom message] (i=9) SUBFAIL test_skip_with_failure.py::T::test_foo - AssertionError: assert 9 < 4",
480+
r"[custom message] (i=4) SUBFAIL test_skip_with_failure.py::T::test_foo"
481+
r" - AssertionError: assert 4 < 4",
482+
r"[custom message] (i=9) SUBFAIL test_skip_with_failure.py::T::test_foo"
483+
r" - AssertionError: assert 9 < 4",
482484
r".* 6 failed, 1 passed, 4 skipped in .*",
483485
]
484486
)
@@ -542,8 +544,10 @@ def test_foo(self):
542544
[
543545
r"test_skip_with_failure_and_non_subskip.py::T::test_foo \[custom message\] \(i=4\) SUBFAIL .*",
544546
r"test_skip_with_failure_and_non_subskip.py::T::test_foo SKIPPED \(skip the test\)",
545-
r"\[custom message\] \(i=0\) SUBSKIP \[1\] test_skip_with_failure_and_non_subskip.py:5: skip subtest i=3",
546-
r"\[custom message\] \(i=0\) SUBSKIP \[1\] test_skip_with_failure_and_non_subskip.py:5: skip the test",
547+
r"\[custom message\] \(i=0\) SUBSKIP \[1\] test_skip_with_failure_and_non_subskip.py:5:"
548+
r" skip subtest i=3",
549+
r"\[custom message\] \(i=0\) SUBSKIP \[1\] test_skip_with_failure_and_non_subskip.py:5:"
550+
r" skip the test",
547551
r"\[custom message\] \(i=4\) SUBFAIL test_skip_with_failure_and_non_subskip.py::T::test_foo",
548552
r".* 6 failed, 5 skipped in .*",
549553
]
@@ -555,7 +559,8 @@ def test_foo(self):
555559
[
556560
r"test_skip_with_failure_and_non_subskip.py::T::test_foo \[custom message\] \(i=4\) SUBFAIL .*",
557561
r"test_skip_with_failure_and_non_subskip.py::T::test_foo SKIPPED \(skip the test\).*",
558-
r"\[custom message\] \(i=3\) SUBSKIP test_skip_with_failure_and_non_subskip.py::T::test_foo - Skipped: skip subtest i=3",
562+
r"\[custom message\] \(i=3\) SUBSKIP test_skip_with_failure_and_non_subskip.py::T::test_foo"
563+
r" - Skipped: skip subtest i=3",
559564
r"SKIPPED test_skip_with_failure_and_non_subskip.py::T::test_foo - Skipped: skip the test",
560565
r"\[custom message\] \(i=4\) SUBFAIL test_skip_with_failure_and_non_subskip.py::T::test_foo",
561566
r".* 6 failed, 5 skipped in .*",
@@ -748,9 +753,7 @@ class TestDebugging:
748753
"""Check --pdb support for subtests fixture and TestCase.subTest."""
749754

750755
class _FakePdb:
751-
"""
752-
Fake debugger class implementation that tracks which methods were called on it.
753-
"""
756+
"""Fake debugger class implementation that tracks which methods were called on it."""
754757

755758
quitting: bool = False
756759
calls: list[str] = []
@@ -813,9 +816,7 @@ def runpytest_and_check_pdb(
813816

814817

815818
def test_exitfirst(pytester: pytest.Pytester) -> None:
816-
"""
817-
Validate that when passing --exitfirst the test exits after the first failed subtest.
818-
"""
819+
"""Validate that when passing --exitfirst the test exits after the first failed subtest."""
819820
pytester.makepyfile(
820821
"""
821822
def test_foo(subtests):

0 commit comments

Comments
 (0)