Skip to content

Commit c02c55e

Browse files
authored
Fix off by one error when using -x (#139)
1 parent cbff3e1 commit c02c55e

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGELOG
22
=========
33

4+
UNRELEASED
5+
----------
6+
7+
* Fixed bug were an extra test would execute when ``-x/--exitfirst`` was used (`#139`_).
8+
9+
.. _#139: https://github.com/pytest-dev/pytest-subtests/pull/139
10+
411
0.13.0 (2024-07-07)
512
-------------------
613

src/pytest_subtests/plugin.py

Lines changed: 3 additions & 3 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,6 +272,9 @@ def __exit__(
275272
node=self.request.node, call=call_info, report=sub_report
276273
)
277274

275+
if exc_val is not None:
276+
if self.request.session.shouldfail:
277+
return False
278278
return True
279279

280280

tests/test_subtests.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,15 +593,16 @@ def test_foo(subtests):
593593
assert False
594594
595595
with subtests.test("sub2"):
596-
pass
596+
assert False
597597
"""
598598
)
599599
result = pytester.runpytest("--exitfirst")
600-
assert result.parseoutcomes()["failed"] == 1
600+
assert result.parseoutcomes()["failed"] == 2
601601
result.stdout.fnmatch_lines(
602602
[
603603
"*[[]sub1[]] SUBFAIL test_exitfirst.py::test_foo - assert False*",
604-
"* stopping after 1 failures*",
604+
"FAILED test_exitfirst.py::test_foo - assert False",
605+
"* stopping after 2 failures*",
605606
],
606607
consecutive=True,
607608
)

0 commit comments

Comments
 (0)