Skip to content

Commit cf7f1fa

Browse files
committed
Passing subtests no longer turn the output yellow (similar to warnings)
Fix #86
1 parent 8d43489 commit cf7f1fa

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
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"):

0 commit comments

Comments
 (0)