From dc7bf518b33b97b08ce54e3ae061c200181757d3 Mon Sep 17 00:00:00 2001 From: Alexandre Mulatinho Date: Wed, 18 Dec 2019 15:15:53 -0300 Subject: [PATCH] pytester: quick fix error introduced in #5990 - added a test to check this condition Signed-off-by: Alexandre Mulatinho --- changelog/6532.bugfix.rst | 1 + src/_pytest/pytester.py | 2 +- testing/test_pytester.py | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 changelog/6532.bugfix.rst diff --git a/changelog/6532.bugfix.rst b/changelog/6532.bugfix.rst new file mode 100644 index 000000000..dbfa0534d --- /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 f44a69a95..490649ad7 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -456,7 +456,7 @@ class RunResult: "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 5bdbacdd0..fe0002b64 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)