Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing subtests no longer turn the output yellow (similar to warnings) #92

Merged
merged 2 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
----------

* 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)
-------------------
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
12 changes: 6 additions & 6 deletions tests/test_subtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) *",
Expand All @@ -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*",
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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
+ [
Expand Down Expand Up @@ -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*",
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ passenv =
TRAVIS
PYTEST_ADDOPTS
deps =
pytest-xdist>=1.28
pytest-xdist>=3.3.0

commands =
pytest {posargs:tests}