diff --git a/changelog/6532.bugfix.rst b/changelog/6532.bugfix.rst new file mode 100644 index 00000000000..dbfa0534ddb --- /dev/null +++ b/changelog/6532.bugfix.rst @@ -0,0 +1 @@ +Fix problem with ``testdir`` not recognizing errors correctly in runs with a single test. diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index f44a69a951c..490649ad7da 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -456,7 +456,7 @@ def assert_outcomes( "passed": d.get("passed", 0), "skipped": d.get("skipped", 0), "failed": d.get("failed", 0), - "error": d.get("error", 0), + "error": d.get("error", 0) + d.get("errors", 0), "xpassed": d.get("xpassed", 0), "xfailed": d.get("xfailed", 0), } diff --git a/testing/test_pytester.py b/testing/test_pytester.py index 5bdbacdd0ed..fe0002b6453 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -682,3 +682,23 @@ def test_run_result_repr(): repr(r) == "" ) + + +def test_run_pytester_with_single_test(testdir): + testcode = """ + import pytest + + @pytest.fixture + def bad_fixture(): + raise Exception("bad") + + def test_error1(bad_fixture): + pass + + def test_error2(bad_fixture): + pass + """ + + testdir.makepyfile(testcode) + result = testdir.runpytest() + result.assert_outcomes(error=2)