From ed5e89a82938c7b6530c477ccc6e5ddb47e473be Mon Sep 17 00:00:00 2001 From: Isaac Barrezueta Date: Sun, 9 Feb 2020 17:27:12 -0500 Subject: [PATCH 1/3] Added new test case for single error --- testing/test_pytester.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/testing/test_pytester.py b/testing/test_pytester.py index 35a06e33a32..e70fdd7fae7 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -709,9 +709,26 @@ def test_error2(bad_fixture): result = testdir.runpytest(str(p1)) result.assert_outcomes(error=2) - assert result.parseoutcomes() == {"error": 2} + assert result.parseoutcomes() == {"errors": 2} +def test_testdir_outcomes_with_single_error(testdir): + p1 = testdir.makepyfile( + """ + import pytest + + @pytest.fixture + def bad_fixture(): + raise Exception("bad") + + def test_error1(bad_fixture): + pass + """ + ) + result = testdir.runpytest(str(p1)) + result.assert_outcomes(error=1) + assert result.parseoutcomes() == {"errors": 1} + def test_makefile_joins_absolute_path(testdir: Testdir) -> None: absfile = testdir.tmpdir / "absfile" if sys.platform == "win32": From 516909227b59617e1ef4fcb066e0b80776f34adb Mon Sep 17 00:00:00 2001 From: Jordan Wilson Date: Mon, 10 Feb 2020 17:45:59 -0500 Subject: [PATCH 2/3] Fixing errors for plurality --- src/_pytest/main.py | 5 +---- src/_pytest/terminal.py | 16 ++-------------- testing/acceptance_test.py | 4 ++-- testing/python/collect.py | 2 +- testing/python/fixtures.py | 2 +- testing/test_assertrewrite.py | 2 +- testing/test_capture.py | 2 +- testing/test_collection.py | 6 +++--- testing/test_doctest.py | 2 +- 9 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index e5666da9fce..887932b7e8d 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -270,10 +270,7 @@ def pytest_collection(session): def pytest_runtestloop(session): if session.testsfailed and not session.config.option.continue_on_collection_errors: - raise session.Interrupted( - "%d error%s during collection" - % (session.testsfailed, "s" if session.testsfailed != 1 else "") - ) + raise session.Interrupted("%d error%s during collection" % session.testfailed) if session.config.option.collectonly: return True diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 2206b5d98fa..b655be21a54 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -558,7 +558,7 @@ def report_collect(self, final=False): str(self._numcollected) + " item" + ("" if self._numcollected == 1 else "s") ) if errors: - line += " / %d error%s" % (errors, "s" if errors != 1 else "") + line += " / %d errors" % errors if deselected: line += " / %d deselected" % deselected if skipped: @@ -1087,18 +1087,6 @@ def _folded_skips(skipped): _color_for_type_default = "yellow" -def _make_plural(count, noun): - # No need to pluralize words such as `failed` or `passed`. - if noun not in ["error", "warnings"]: - return count, noun - - # The `warnings` key is plural. To avoid API breakage, we keep it that way but - # set it to singular here so we can determine plurality in the same way as we do - # for `error`. - noun = noun.replace("warnings", "warning") - - return count, noun + "s" if count != 1 else noun - def _get_main_color(stats) -> Tuple[str, List[str]]: known_types = ( @@ -1136,7 +1124,7 @@ def build_summary_stats_line(stats): ) color = _color_for_type.get(key, _color_for_type_default) markup = {color: True, "bold": color == main_color} - parts.append(("%d %s" % _make_plural(count, key), markup)) + parts.append(("%d %s" % (count, key), markup)) if not parts: parts = [("no tests ran", {_color_for_type_default: True})] diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 9bc7367c830..e2098f2ef4f 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -636,7 +636,7 @@ def test_pyargs_importerror(self, testdir, monkeypatch): result = testdir.runpytest("--pyargs", "tpkg.test_hello", syspathinsert=True) assert result.ret != 0 - result.stdout.fnmatch_lines(["collected*0*items*/*1*error"]) + result.stdout.fnmatch_lines(["collected*0*items*/*1*errors"]) def test_pyargs_only_imported_once(self, testdir): pkg = testdir.mkpydir("foo") @@ -963,7 +963,7 @@ def test_with_failing_collection(self, testdir): testdir.makepyfile(test_collecterror="""xyz""") result = testdir.runpytest("--durations=2", "-k test_1") assert result.ret == 2 - result.stdout.fnmatch_lines(["*Interrupted: 1 error during collection*"]) + result.stdout.fnmatch_lines(["*Interrupted: 1 errors during collection*"]) # Collection errors abort test execution, therefore no duration is # output result.stdout.no_fnmatch_line("*duration*") diff --git a/testing/python/collect.py b/testing/python/collect.py index f38c309b25b..227b8a7e45c 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -1167,7 +1167,7 @@ def test_real(): [ "*collected 1 item*", "*test_dont_collect_non_function_callable.py:2: *cannot collect 'test_a' because it is not a function*", - "*1 passed, 1 warning in *", + "*1 passed, 1 warnings in *", ] ) diff --git a/testing/python/fixtures.py b/testing/python/fixtures.py index bfbe359515c..72df4408dac 100644 --- a/testing/python/fixtures.py +++ b/testing/python/fixtures.py @@ -3113,7 +3113,7 @@ def test_3(): *KeyError* *ERROR*teardown*test_2* *KeyError* - *3 pass*2 errors* + *3 pass*2 error* """ ) diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index 8490a59e640..6b6b9d42408 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -122,7 +122,7 @@ def test_dont_rewrite_plugin(self, testdir): } testdir.makepyfile(**contents) result = testdir.runpytest_subprocess() - assert "warning" not in "".join(result.outlines) + assert "warnings" not in "".join(result.outlines) def test_rewrites_plugin_as_a_package(self, testdir): pkgdir = testdir.mkpydir("plugin") diff --git a/testing/test_capture.py b/testing/test_capture.py index 9261c8441ed..f29b92ba7cf 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -453,7 +453,7 @@ def test_two(capfd, capsys): "E*capfd*capsys*same*time*", "*ERROR*setup*test_two*", "E*capsys*capfd*same*time*", - "*2 errors*", + "*2 error*", ] ) diff --git a/testing/test_collection.py b/testing/test_collection.py index 5073f675e52..e2b9f715ee6 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -908,7 +908,7 @@ def test_continue_on_collection_errors(testdir): assert res.ret == 1 res.stdout.fnmatch_lines( - ["collected 2 items / 2 errors", "*1 failed, 1 passed, 2 errors*"] + ["collected 2 items / 2 errors", "*1 failed, 1 passed, 2 error*"] ) @@ -925,7 +925,7 @@ def test_continue_on_collection_errors_maxfail(testdir): res = testdir.runpytest("--continue-on-collection-errors", "--maxfail=3") assert res.ret == 1 - res.stdout.fnmatch_lines(["collected 2 items / 2 errors", "*1 failed, 2 errors*"]) + res.stdout.fnmatch_lines(["collected 2 items / 2 errors", "*1 failed, 2 error*"]) def test_fixture_scope_sibling_conftests(testdir): @@ -1269,7 +1269,7 @@ def test_collector_respects_tbstyle(testdir): ' File "*/test_collector_respects_tbstyle.py", line 1, in ', " assert 0", "AssertionError: assert 0", - "*! Interrupted: 1 error during collection !*", + "*! Interrupted: 1 errors during collection !*", "*= 1 error in *", ] ) diff --git a/testing/test_doctest.py b/testing/test_doctest.py index bd214e3dea0..dd0d880beac 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -389,7 +389,7 @@ def test_doctest_unex_importerror_with_module(self, testdir): [ "*ERROR collecting hello.py*", "*{e}: No module named *asdals*".format(e=MODULE_NOT_FOUND_ERROR), - "*Interrupted: 1 error during collection*", + "*Interrupted: 1 errors during collection*", ] ) From 04e7422a4f738661c686e3b185e0749def9eba62 Mon Sep 17 00:00:00 2001 From: Jordan Wilson Date: Tue, 11 Feb 2020 18:45:19 -0500 Subject: [PATCH 3/3] Make changes to this file --- src/_pytest/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 887932b7e8d..5ae46e5907f 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -270,7 +270,7 @@ def pytest_collection(session): def pytest_runtestloop(session): if session.testsfailed and not session.config.option.continue_on_collection_errors: - raise session.Interrupted("%d error%s during collection" % session.testfailed) + raise session.Interrupted("%d errors during collection" % session.testfailed) if session.config.option.collectonly: return True