diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 647c3ee..65df75d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,9 +4,13 @@ CHANGELOG UNRELEASED ---------- +* Passing subtests no longer turn the pytest output to yellow (as if warnings have been issued) (`#86`_). Thanks to `Andrew-Brock`_ for providing the solution. * Now the ``msg`` contents of a subtest is displayed when running pytest with ``-v`` (`#6`_). .. _#6: https://github.com/pytest-dev/pytest-subtests/issues/6 +.. _#86: https://github.com/pytest-dev/pytest-subtests/issues/86 + +.. _`Andrew-Brock`: https://github.com/Andrew-Brock 0.10.0 (2022-02-15) ------------------- diff --git a/pytest_subtests.py b/pytest_subtests.py index 1ee4fb2..1a279e2 100644 --- a/pytest_subtests.py +++ b/pytest_subtests.py @@ -97,6 +97,27 @@ def pytest_configure(config): TestCaseFunction.addSubTest = _addSubTest TestCaseFunction.failfast = False + # Hack (#86): the terminal does not know about the "subtests" + # status, so it will by default turn the output to yellow. + # This forcibly adds the new 'subtests' status. + import _pytest.terminal + + new_types = tuple( + f"subtests {outcome}" for outcome in ("passed", "failed", "skipped") + ) + # We need to check if we are not re-adding because we run our own tests + # with pytester in-process mode, so this will be called multiple times. + if new_types[0] not in _pytest.terminal.KNOWN_TYPES: + _pytest.terminal.KNOWN_TYPES = _pytest.terminal.KNOWN_TYPES + new_types + + _pytest.terminal._color_for_type.update( + { + f"subtests {outcome}": _pytest.terminal._color_for_type[outcome] + for outcome in ("passed", "failed", "skipped") + if outcome in _pytest.terminal._color_for_type + } + ) + def pytest_unconfigure(): if hasattr(TestCaseFunction, "addSubTest"): diff --git a/tests/test_subtests.py b/tests/test_subtests.py index 219b78a..0ca0317 100644 --- a/tests/test_subtests.py +++ b/tests/test_subtests.py @@ -29,7 +29,7 @@ def test_simple_terminal_normal(self, simple_script, testdir, mode): else: pytest.importorskip("xdist") result = testdir.runpytest("-n1") - expected_lines = ["gw0 [1]"] + expected_lines = ["1 worker [1 item]"] expected_lines += [ "* test_foo [[]custom[]] (i=1) *", @@ -54,7 +54,7 @@ def test_simple_terminal_verbose(self, simple_script, testdir, mode): pytest.importorskip("xdist") result = testdir.runpytest("-n1", "-v") expected_lines = [ - "gw0 [1]", + "1 worker [1 item]", "*gw0*100%* test_simple_terminal_verbose.py::test_foo*", "*gw0*100%* test_simple_terminal_verbose.py::test_foo*", "*gw0*100%* test_simple_terminal_verbose.py::test_foo*", @@ -87,7 +87,7 @@ def test_foo(subtests): else: pytest.importorskip("xdist") result = testdir.runpytest("-n1") - expected_lines = ["gw0 [1]"] + expected_lines = ["1 worker [1 item]"] expected_lines += ["* 1 passed, 3 skipped, 2 subtests passed in *"] result.stdout.fnmatch_lines(expected_lines) @@ -108,7 +108,7 @@ def test_foo(subtests): else: pytest.importorskip("xdist") result = testdir.runpytest("-n1") - expected_lines = ["gw0 [1]"] + expected_lines = ["1 worker [1 item]"] expected_lines += ["* 1 passed, 3 xfailed, 2 subtests passed in *"] result.stdout.fnmatch_lines(expected_lines) @@ -159,7 +159,7 @@ def test_simple_terminal_normal(self, simple_script, testdir, runner): else: pytest.importorskip("xdist") result = testdir.runpytest(simple_script, "-n1") - expected_lines = ["gw0 [1]"] + expected_lines = ["1 worker [1 item]"] result.stdout.fnmatch_lines( expected_lines + [ @@ -201,7 +201,7 @@ def test_simple_terminal_verbose(self, simple_script, testdir, runner): pytest.importorskip("xdist") result = testdir.runpytest(simple_script, "-n1", "-v") expected_lines = [ - "gw0 [1]", + "1 worker [1 item]", "*gw0*100%* SUBFAIL test_simple_terminal_verbose.py::T::test_foo*", "*gw0*100%* SUBFAIL test_simple_terminal_verbose.py::T::test_foo*", "*gw0*100%* PASSED test_simple_terminal_verbose.py::T::test_foo*", diff --git a/tox.ini b/tox.ini index f7d9c72..a2d7608 100644 --- a/tox.ini +++ b/tox.ini @@ -8,7 +8,7 @@ passenv = TRAVIS PYTEST_ADDOPTS deps = - pytest-xdist>=1.28 + pytest-xdist>=3.3.0 commands = pytest {posargs:tests}