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

Conversation

giampaolo
Copy link

See #198.

giampaolo and others added 3 commits June 26, 2025 00:36
@giampaolo giampaolo mentioned this pull request Jun 25, 2025
Signed-off-by: Giampaolo Rodola <[email protected]>
Signed-off-by: Giampaolo Rodola <[email protected]>
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @giampaolo!

Could you please also add a test case using the option, and ensuring that the subtests do not show up in the output? It should also show subtests if they fail or skip, regardless of the option. Feel free to add more than one test.

Thanks!

@giampaolo
Copy link
Author

giampaolo commented Jul 1, 2025

I've tried by installing my local branch with python3 -m pip install -e . (editable / dev mode) but it keeps using the module installed at system level. :-\

The way I run the new test is:

 python3 -m pytest --tb=short --no-header -v -s  tests/test_subtests.py::TestFixture::test_xxx

...and the draft of the new test looks like:

diff --git a/tests/test_subtests.py b/tests/test_subtests.py
index bd5cef9..307953d 100644
--- a/tests/test_subtests.py
+++ b/tests/test_subtests.py
@@ -156,6 +156,31 @@ class TestFixture:
         expected_lines += ["* 1 passed *"]
         result.stdout.fnmatch_lines(expected_lines)
 
+    def test_xxx(self, pytester: pytest.Pytester, mode: Literal["normal", "xdist"]):
+        pytester.makepyfile(
+            """
+            import pytest
+
+            def test_foo(subtests):
+                for i in range(5):
+                    with subtests.test(msg="custom", i=i):
+                        if i % 2 == 0:
+                            pytest.fail('even number')
+        """
+        )
+        expected_lines = [
+            "[custom] (i=0) SUBFAIL test_xxx.py::test_foo - Failed: even number",
+            "[custom] (i=2) SUBFAIL test_xxx.py::test_foo - Failed: even number",
+            "[custom] (i=4) SUBFAIL test_xxx.py::test_foo - Failed: even number",
+        ]
+        # result = pytester.runpytest("-v")
+        # result.stdout.fnmatch_lines(expected_lines)
+
+        result = pytester.runpytest("--no-subtests-reports")
+        print(result.stdout.str())
+        # breakpoint()  # XXX
+        # result.stdout.fnmatch_lines(expected_lines)
+
 
 class TestSubTest:
     """

@nicoddemus
Copy link
Member

nicoddemus commented Jul 1, 2025

Good practice is to always use a virtual env:

python3 -m venv .venv
source .venv/bin/activate
pip install -e .
pytest --tb=short --no-header -v -s  tests/test_subtests.py::TestFixture::test_xxx

This way you never install anything in your system Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants