Skip to content

Commit 46eee3f

Browse files
authored
Merge pull request #92 from nicoddemus/yellow-output-86
Passing subtests no longer turn the output yellow (similar to warnings)
2 parents 5bc0a56 + cf7f1fa commit 46eee3f

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

CHANGELOG.rst

+4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ CHANGELOG
44
UNRELEASED
55
----------
66

7+
* 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.
78
* Now the ``msg`` contents of a subtest is displayed when running pytest with ``-v`` (`#6`_).
89

910
.. _#6: https://github.com/pytest-dev/pytest-subtests/issues/6
11+
.. _#86: https://github.com/pytest-dev/pytest-subtests/issues/86
12+
13+
.. _`Andrew-Brock`: https://github.com/Andrew-Brock
1014

1115
0.10.0 (2022-02-15)
1216
-------------------

pytest_subtests.py

+21
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,27 @@ def pytest_configure(config):
9797
TestCaseFunction.addSubTest = _addSubTest
9898
TestCaseFunction.failfast = False
9999

100+
# Hack (#86): the terminal does not know about the "subtests"
101+
# status, so it will by default turn the output to yellow.
102+
# This forcibly adds the new 'subtests' status.
103+
import _pytest.terminal
104+
105+
new_types = tuple(
106+
f"subtests {outcome}" for outcome in ("passed", "failed", "skipped")
107+
)
108+
# We need to check if we are not re-adding because we run our own tests
109+
# with pytester in-process mode, so this will be called multiple times.
110+
if new_types[0] not in _pytest.terminal.KNOWN_TYPES:
111+
_pytest.terminal.KNOWN_TYPES = _pytest.terminal.KNOWN_TYPES + new_types
112+
113+
_pytest.terminal._color_for_type.update(
114+
{
115+
f"subtests {outcome}": _pytest.terminal._color_for_type[outcome]
116+
for outcome in ("passed", "failed", "skipped")
117+
if outcome in _pytest.terminal._color_for_type
118+
}
119+
)
120+
100121

101122
def pytest_unconfigure():
102123
if hasattr(TestCaseFunction, "addSubTest"):

tests/test_subtests.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_simple_terminal_normal(self, simple_script, testdir, mode):
2929
else:
3030
pytest.importorskip("xdist")
3131
result = testdir.runpytest("-n1")
32-
expected_lines = ["gw0 [1]"]
32+
expected_lines = ["1 worker [1 item]"]
3333

3434
expected_lines += [
3535
"* test_foo [[]custom[]] (i=1) *",
@@ -54,7 +54,7 @@ def test_simple_terminal_verbose(self, simple_script, testdir, mode):
5454
pytest.importorskip("xdist")
5555
result = testdir.runpytest("-n1", "-v")
5656
expected_lines = [
57-
"gw0 [1]",
57+
"1 worker [1 item]",
5858
"*gw0*100%* test_simple_terminal_verbose.py::test_foo*",
5959
"*gw0*100%* test_simple_terminal_verbose.py::test_foo*",
6060
"*gw0*100%* test_simple_terminal_verbose.py::test_foo*",
@@ -87,7 +87,7 @@ def test_foo(subtests):
8787
else:
8888
pytest.importorskip("xdist")
8989
result = testdir.runpytest("-n1")
90-
expected_lines = ["gw0 [1]"]
90+
expected_lines = ["1 worker [1 item]"]
9191
expected_lines += ["* 1 passed, 3 skipped, 2 subtests passed in *"]
9292
result.stdout.fnmatch_lines(expected_lines)
9393

@@ -108,7 +108,7 @@ def test_foo(subtests):
108108
else:
109109
pytest.importorskip("xdist")
110110
result = testdir.runpytest("-n1")
111-
expected_lines = ["gw0 [1]"]
111+
expected_lines = ["1 worker [1 item]"]
112112
expected_lines += ["* 1 passed, 3 xfailed, 2 subtests passed in *"]
113113
result.stdout.fnmatch_lines(expected_lines)
114114

@@ -159,7 +159,7 @@ def test_simple_terminal_normal(self, simple_script, testdir, runner):
159159
else:
160160
pytest.importorskip("xdist")
161161
result = testdir.runpytest(simple_script, "-n1")
162-
expected_lines = ["gw0 [1]"]
162+
expected_lines = ["1 worker [1 item]"]
163163
result.stdout.fnmatch_lines(
164164
expected_lines
165165
+ [
@@ -201,7 +201,7 @@ def test_simple_terminal_verbose(self, simple_script, testdir, runner):
201201
pytest.importorskip("xdist")
202202
result = testdir.runpytest(simple_script, "-n1", "-v")
203203
expected_lines = [
204-
"gw0 [1]",
204+
"1 worker [1 item]",
205205
"*gw0*100%* SUBFAIL test_simple_terminal_verbose.py::T::test_foo*",
206206
"*gw0*100%* SUBFAIL test_simple_terminal_verbose.py::T::test_foo*",
207207
"*gw0*100%* PASSED test_simple_terminal_verbose.py::T::test_foo*",

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ passenv =
88
TRAVIS
99
PYTEST_ADDOPTS
1010
deps =
11-
pytest-xdist>=1.28
11+
pytest-xdist>=3.3.0
1212

1313
commands =
1414
pytest {posargs:tests}

0 commit comments

Comments
 (0)