Skip to content

Commit a63b021

Browse files
committed
Docs
1 parent 66313f2 commit a63b021

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

doc/en/how-to/subtests.rst

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ Subtests are an alternative to parametrization, particularly useful when the exa
1616

1717
.. code-block:: python
1818
19-
def contains_docstring(p: Path) -> bool:
20-
"""Return True if the given Python file contains a top-level docstring."""
21-
...
19+
# content of test_subtest.py
2220
2321
24-
def test_py_files_contain_docstring(subtests: pytest.Subtests) -> None:
25-
for path in Path.cwd().glob("*.py"):
26-
with subtests.test(path=str(path)):
27-
assert contains_docstring(path)
22+
def test(subtests):
23+
for i in range(5):
24+
with subtests.test(msg="custom message", i=i):
25+
assert i % 2 == 0
2826
2927
Each assertion failure or error is caught by the context manager and reported individually:
3028

@@ -33,6 +31,12 @@ Each assertion failure or error is caught by the context manager and reported in
3331
$ pytest -q test_subtest.py
3432
3533
34+
In the output above:
35+
36+
* Each subtest is reported with the ``,`` character.
37+
* Subtests are reported first and the "top-level" test is reported at the end on its own.
38+
* Subtest failures are reported as ``SUBFAIL``.
39+
3640
Note that it is possible to use ``subtests`` multiple times in the same test, or even mix and match with normal assertions
3741
outside the ``subtests.test`` block:
3842

@@ -88,3 +92,4 @@ Subtests
8892
* Can be generated dynamically.
8993
* Cannot be referenced individually from the command line.
9094
* Plugins that handle test execution cannot target individual subtests.
95+
* An assertion failure inside a subtest does not interrupt the test, letting users see all failures in the same report.

0 commit comments

Comments
 (0)