Skip to content

Commit d44034d

Browse files
committed
exit parent test immediately
1 parent 7e64048 commit d44034d

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/pytest_subtests/plugin.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,6 @@ def __exit__(
242242
__tracebackhide__ = True
243243
try:
244244
if exc_val is not None:
245-
if self.request.session.shouldfail:
246-
return False
247-
248245
exc_info = ExceptionInfo.from_exception(exc_val)
249246
else:
250247
exc_info = None
@@ -275,7 +272,9 @@ def __exit__(
275272
node=self.request.node, call=call_info, report=sub_report
276273
)
277274

278-
return True
275+
if exc_val is not None:
276+
if self.request.session.shouldfail:
277+
pytest.exit(reason=f"subtest failed")
279278

280279

281280
def make_call_info(

tests/test_subtests.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,13 @@ def test_foo(subtests):
593593
assert False
594594
595595
with subtests.test("sub2"):
596-
assert False
596+
assert True
597+
598+
assert False, "This would fail the parent, but shouldn't be reached"
597599
"""
598600
)
599601
result = pytester.runpytest("--exitfirst")
600-
assert result.parseoutcomes()["failed"] == 1
602+
assert result.parseoutcomes()["failed"] == 1 # sub1 failed
601603
result.stdout.fnmatch_lines(
602604
[
603605
"*[[]sub1[]] SUBFAIL test_exitfirst.py::test_foo - assert False*",
@@ -606,3 +608,4 @@ def test_foo(subtests):
606608
consecutive=True,
607609
)
608610
result.stdout.no_fnmatch_line("*sub2*") # sub2 not executed.
611+
result.stdout.no_fnmatch_line("*This would fail the parent*") # parent test neither passed nor failed

0 commit comments

Comments
 (0)