From 9c7e3dac2763a8631dc80f5ce21d18c7c430608d Mon Sep 17 00:00:00 2001 From: Max Nikulin Date: Mon, 22 Jun 2020 18:06:18 +0700 Subject: [PATCH] Explicit hint to subtests in progress and summary Use "SUBPASS" and "," for passed subtests instead of general "PASSED", "SUBFAIL" and "u" for failed ones instead of "FAILED". --- pytest_subtests.py | 14 ++++++++++++++ tests/test_subtests.py | 22 +++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/pytest_subtests.py b/pytest_subtests.py index efe2aa7..71a9e3d 100644 --- a/pytest_subtests.py +++ b/pytest_subtests.py @@ -188,3 +188,17 @@ def pytest_report_to_serializable(report): def pytest_report_from_serializable(data): if data.get("_report_type") == "SubTestReport": return SubTestReport._from_json(data) + + +@pytest.hookimpl(tryfirst=True) +def pytest_report_teststatus(report): + if report.when != "call" or not isinstance(report, SubTestReport): + return + + outcome = report.outcome + if report.passed: + return outcome, ",", "SUBPASS" + elif report.skipped: + return outcome, "-", "SUBSKIP" + elif outcome == "failed": + return outcome, "u", "SUBFAIL" diff --git a/tests/test_subtests.py b/tests/test_subtests.py index 415abee..cb2d1a9 100644 --- a/tests/test_subtests.py +++ b/tests/test_subtests.py @@ -41,11 +41,11 @@ def test_simple_terminal_verbose(self, simple_script, testdir, mode): result = testdir.runpytest("-v") expected_lines = [ "*collected 1 item", - "test_simple_terminal_verbose.py::test_foo PASSED *100%*", - "test_simple_terminal_verbose.py::test_foo FAILED *100%*", - "test_simple_terminal_verbose.py::test_foo PASSED *100%*", - "test_simple_terminal_verbose.py::test_foo FAILED *100%*", - "test_simple_terminal_verbose.py::test_foo PASSED *100%*", + "test_simple_terminal_verbose.py::test_foo SUBPASS *100%*", + "test_simple_terminal_verbose.py::test_foo SUBFAIL *100%*", + "test_simple_terminal_verbose.py::test_foo SUBPASS *100%*", + "test_simple_terminal_verbose.py::test_foo SUBFAIL *100%*", + "test_simple_terminal_verbose.py::test_foo SUBPASS *100%*", "test_simple_terminal_verbose.py::test_foo PASSED *100%*", ] else: @@ -168,8 +168,8 @@ def test_simple_terminal_verbose(self, simple_script, testdir, runner): result = testdir.runpytest(simple_script, "-v") expected_lines = [ "*collected 1 item", - "test_simple_terminal_verbose.py::T::test_foo FAILED *100%*", - "test_simple_terminal_verbose.py::T::test_foo FAILED *100%*", + "test_simple_terminal_verbose.py::T::test_foo SUBFAIL *100%*", + "test_simple_terminal_verbose.py::T::test_foo SUBFAIL *100%*", "test_simple_terminal_verbose.py::T::test_foo PASSED *100%*", ] else: @@ -177,8 +177,8 @@ def test_simple_terminal_verbose(self, simple_script, testdir, runner): result = testdir.runpytest(simple_script, "-n1", "-v") expected_lines = [ "gw0 [1]", - "*gw0*100%* FAILED test_simple_terminal_verbose.py::T::test_foo*", - "*gw0*100%* FAILED test_simple_terminal_verbose.py::T::test_foo*", + "*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*", ] result.stdout.fnmatch_lines( @@ -274,8 +274,8 @@ def test_no_capture(self, testdir): [ "start test", "hello stdout A", - "Fhello stdout B", - "Fend test", + "uhello stdout B", + "uend test", "*__ test (i='A') __*", "*__ test (i='B') __*", "*__ test __*",