Skip to content

Commit

Permalink
Explicit hint to subtests in progress and summary
Browse files Browse the repository at this point in the history
Use "SUBPASS" and "," for passed subtests instead of general "PASSED",
"SUBFAIL" and "u" for failed ones instead of "FAILED".
  • Loading branch information
maxnikulin committed Jun 22, 2020
1 parent c1ec643 commit 9c7e3da
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
14 changes: 14 additions & 0 deletions pytest_subtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
22 changes: 11 additions & 11 deletions tests/test_subtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -168,17 +168,17 @@ 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:
pytest.importorskip("xdist")
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(
Expand Down Expand Up @@ -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 __*",
Expand Down

0 comments on commit 9c7e3da

Please sign in to comment.