12
12
13
13
@pytest .mark .parametrize ("mode" , ["normal" , "xdist" ])
14
14
class TestFixture :
15
- """
16
- Tests for ``subtests`` fixture.
17
- """
15
+ """Tests for ``subtests`` fixture."""
18
16
19
17
@pytest .fixture
20
18
def simple_script (self , pytester : pytest .Pytester ) -> None :
@@ -39,7 +37,7 @@ def test_simple_terminal_normal(
39
37
else :
40
38
assert mode == "xdist"
41
39
pytest .importorskip ("xdist" )
42
- result = pytester .runpytest ("-n1" )
40
+ result = pytester .runpytest ("-n1" , "-pxdist.plugin" )
43
41
expected_lines = ["1 worker [1 item]" ]
44
42
45
43
expected_lines += [
@@ -69,7 +67,7 @@ def test_simple_terminal_verbose(
69
67
else :
70
68
assert mode == "xdist"
71
69
pytest .importorskip ("xdist" )
72
- result = pytester .runpytest ("-n1" , "-v" )
70
+ result = pytester .runpytest ("-n1" , "-v" , "-pxdist.plugin" )
73
71
expected_lines = [
74
72
"1 worker [1 item]" ,
75
73
"*gw0*100%* test_simple_terminal_verbose.py::test_foo*" ,
@@ -106,7 +104,7 @@ def test_foo(subtests):
106
104
else :
107
105
assert mode == "xdist"
108
106
pytest .importorskip ("xdist" )
109
- result = pytester .runpytest ("-n1" )
107
+ result = pytester .runpytest ("-n1" , "-pxdist.plugin" )
110
108
expected_lines = ["1 worker [1 item]" ]
111
109
expected_lines += ["* 1 passed, 3 skipped, 2 subtests passed in *" ]
112
110
result .stdout .fnmatch_lines (expected_lines )
@@ -130,7 +128,7 @@ def test_foo(subtests):
130
128
else :
131
129
assert mode == "xdist"
132
130
pytest .importorskip ("xdist" )
133
- result = pytester .runpytest ("-n1" )
131
+ result = pytester .runpytest ("-n1" , "-pxdist.plugin" )
134
132
expected_lines = ["1 worker [1 item]" ]
135
133
expected_lines += ["* 1 passed, 2 subtests passed, 3 subtests xfailed in *" ]
136
134
result .stdout .fnmatch_lines (expected_lines )
@@ -152,7 +150,7 @@ def test_typing_exported(subtests: SubTests) -> None:
152
150
else :
153
151
assert mode == "xdist"
154
152
pytest .importorskip ("xdist" )
155
- result = pytester .runpytest ("-n1" )
153
+ result = pytester .runpytest ("-n1" , "-pxdist.plugin" )
156
154
expected_lines = ["1 worker [1 item]" ]
157
155
expected_lines += ["* 1 passed *" ]
158
156
result .stdout .fnmatch_lines (expected_lines )
@@ -215,9 +213,7 @@ def test_foo(subtests):
215
213
216
214
217
215
class TestSubTest :
218
- """
219
- Test Test.subTest functionality.
220
- """
216
+ """Test.subTest functionality."""
221
217
222
218
@pytest .fixture
223
219
def simple_script (self , pytester : pytest .Pytester ) -> Path :
@@ -264,11 +260,11 @@ def test_simple_terminal_normal(
264
260
else :
265
261
assert runner == "pytest-xdist"
266
262
pytest .importorskip ("xdist" )
267
- result = pytester .runpytest (simple_script , "-n1" )
263
+ result = pytester .runpytest (simple_script , "-n1" , "-pxdist.plugin" )
268
264
expected_lines = ["1 worker [1 item]" ]
269
265
result .stdout .fnmatch_lines (
270
- expected_lines
271
- + [
266
+ [
267
+ * expected_lines ,
272
268
"* T.test_foo [[]custom[]] (i=1) *" ,
273
269
"E * AssertionError: 1 != 0" ,
274
270
"* T.test_foo [[]custom[]] (i=3) *" ,
@@ -310,16 +306,18 @@ def test_simple_terminal_verbose(
310
306
else :
311
307
assert runner == "pytest-xdist"
312
308
pytest .importorskip ("xdist" )
313
- result = pytester .runpytest (simple_script , "-n1" , "-v" )
309
+ result = pytester .runpytest (
310
+ simple_script , "-n1" , "-v" , "-pxdist.plugin"
311
+ )
314
312
expected_lines = [
315
313
"1 worker [1 item]" ,
316
314
"*gw0*100%* SUBFAIL test_simple_terminal_verbose.py::T::test_foo*" ,
317
315
"*gw0*100%* SUBFAIL test_simple_terminal_verbose.py::T::test_foo*" ,
318
316
"*gw0*100%* PASSED test_simple_terminal_verbose.py::T::test_foo*" ,
319
317
]
320
318
result .stdout .fnmatch_lines (
321
- expected_lines
322
- + [
319
+ [
320
+ * expected_lines ,
323
321
"* T.test_foo [[]custom[]] (i=1) *" ,
324
322
"E * AssertionError: 1 != 0" ,
325
323
"* T.test_foo [[]custom[]] (i=3) *" ,
@@ -470,15 +468,19 @@ def test_foo(self):
470
468
result = pytester .runpytest (p , "-v" , "-rsf" )
471
469
result .stdout .re_match_lines (
472
470
[
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\) .*" ,
475
475
r"test_skip_with_failure.py::T::test_foo \[custom message\] \(i=4\) SUBFAIL .*" ,
476
476
r"test_skip_with_failure.py::T::test_foo \[custom message\] \(i=9\) SUBFAIL .*" ,
477
477
"test_skip_with_failure.py::T::test_foo PASSED .*" ,
478
478
r"[custom message] (i=0) SUBSKIP [1] test_skip_with_failure.py:5: skip subtest i=0" ,
479
479
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" ,
482
484
r".* 6 failed, 1 passed, 4 skipped in .*" ,
483
485
]
484
486
)
@@ -542,8 +544,10 @@ def test_foo(self):
542
544
[
543
545
r"test_skip_with_failure_and_non_subskip.py::T::test_foo \[custom message\] \(i=4\) SUBFAIL .*" ,
544
546
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" ,
547
551
r"\[custom message\] \(i=4\) SUBFAIL test_skip_with_failure_and_non_subskip.py::T::test_foo" ,
548
552
r".* 6 failed, 5 skipped in .*" ,
549
553
]
@@ -555,7 +559,8 @@ def test_foo(self):
555
559
[
556
560
r"test_skip_with_failure_and_non_subskip.py::T::test_foo \[custom message\] \(i=4\) SUBFAIL .*" ,
557
561
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" ,
559
564
r"SKIPPED test_skip_with_failure_and_non_subskip.py::T::test_foo - Skipped: skip the test" ,
560
565
r"\[custom message\] \(i=4\) SUBFAIL test_skip_with_failure_and_non_subskip.py::T::test_foo" ,
561
566
r".* 6 failed, 5 skipped in .*" ,
@@ -748,9 +753,7 @@ class TestDebugging:
748
753
"""Check --pdb support for subtests fixture and TestCase.subTest."""
749
754
750
755
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."""
754
757
755
758
quitting : bool = False
756
759
calls : list [str ] = []
@@ -813,9 +816,7 @@ def runpytest_and_check_pdb(
813
816
814
817
815
818
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."""
819
820
pytester .makepyfile (
820
821
"""
821
822
def test_foo(subtests):
0 commit comments