diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 39601f5..10e726a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,13 @@ CHANGELOG ========= +UNRELEASED +---------- + +* Fixed bug were an extra test would execute when ``-x/--exitfirst`` was used (`#139`_). + +.. _#139: https://github.com/pytest-dev/pytest-subtests/pull/139 + 0.13.0 (2024-07-07) ------------------- diff --git a/src/pytest_subtests/plugin.py b/src/pytest_subtests/plugin.py index fe77783..9914800 100644 --- a/src/pytest_subtests/plugin.py +++ b/src/pytest_subtests/plugin.py @@ -242,9 +242,6 @@ def __exit__( __tracebackhide__ = True try: if exc_val is not None: - if self.request.session.shouldfail: - return False - exc_info = ExceptionInfo.from_exception(exc_val) else: exc_info = None @@ -275,6 +272,9 @@ def __exit__( node=self.request.node, call=call_info, report=sub_report ) + if exc_val is not None: + if self.request.session.shouldfail: + return False return True diff --git a/tests/test_subtests.py b/tests/test_subtests.py index 2f1463a..e0607e5 100644 --- a/tests/test_subtests.py +++ b/tests/test_subtests.py @@ -593,15 +593,16 @@ def test_foo(subtests): assert False with subtests.test("sub2"): - pass + assert False """ ) result = pytester.runpytest("--exitfirst") - assert result.parseoutcomes()["failed"] == 1 + assert result.parseoutcomes()["failed"] == 2 result.stdout.fnmatch_lines( [ "*[[]sub1[]] SUBFAIL test_exitfirst.py::test_foo - assert False*", - "* stopping after 1 failures*", + "FAILED test_exitfirst.py::test_foo - assert False", + "* stopping after 2 failures*", ], consecutive=True, )