Skip to content

Commit

Permalink
Passing subtests no longer turn the output yellow (similar to warnings)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed May 13, 2023
1 parent 5bc0a56 commit 3e1f9e8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ CHANGELOG
UNRELEASED
----------

* Passed 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)
-------------------
Expand Down
21 changes: 21 additions & 0 deletions pytest_subtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down

0 comments on commit 3e1f9e8

Please sign in to comment.