Skip to content

Add --no-subtest-reports CLI opt #199

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
CHANGELOG
=========

0.14.3 (UNRELEASED)
-------------------

*XXXX-XX-XX*

* Added experimental ``--no-subtest-reports`` CLI option. This disables
subtests output unless it's a failed subtest. (`#198`_)

.. _#198: https://github.com/pytest-dev/pytest-subtests/pull/198

0.14.2
------

Expand Down
15 changes: 14 additions & 1 deletion src/pytest_subtests/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ def pytest_addoption(parser: pytest.Parser) -> None:
default=False,
help="Disables subtest output 'dots' in non-verbose mode (EXPERIMENTAL)",
)
group.addoption(
"--no-subtests-reports",
action="store_true",
dest="no_subtests_reports",
default=False,
help="Disables subtest output unless it's a failed subtest (EXPERIMENTAL)",
)


@attr.s
Expand Down Expand Up @@ -459,9 +466,12 @@ def pytest_report_teststatus(

outcome = report.outcome
description = report.sub_test_description()
no_output = ("", "", "")

if hasattr(report, "wasxfail"):
if outcome == "skipped":
if config.option.no_subtests_reports and outcome != "skipped":
return no_output
elif outcome == "skipped":
category = "xfailed"
short = "y" # x letter is used for regular xfail, y for subtest xfail
status = "SUBXFAIL"
Expand All @@ -476,6 +486,9 @@ def pytest_report_teststatus(
return None
short = "" if config.option.no_subtests_shortletter else short
return f"subtests {category}", short, f"{description} {status}"

if config.option.no_subtests_reports and outcome != "failed":
return no_output
elif report.passed:
short = "" if config.option.no_subtests_shortletter else ","
return f"subtests {outcome}", short, f"{description} SUBPASS"
Expand Down