-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): add subtests to framework tests as an example
Added a new test class `TestSubtests` to verify outcomes using subtests.
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
import pytest_subtests | ||
|
||
|
||
class TestSubtests: | ||
def test_outcomes( | ||
self, | ||
subtests: pytest_subtests.SubTests, | ||
): | ||
xfail_msgs = [] | ||
|
||
# In subtest, don't return any other outcome than success or failure. | ||
# Allure doesn't work well with subtests. It will use outcome of the first non-successful | ||
# subtest as the overall test outcome. | ||
# Therefore skiped / xfailed subtests could mask subtest failures. As a workaround, | ||
# record the outcome of the subtest and use it as the outcome of the main test. | ||
def _subtest(num: int) -> None: | ||
if num > 200: | ||
xfail_msgs.append(f"{num} > 200") | ||
|
||
for n in (100, 200, 300, 500): | ||
with subtests.test(msg="check num", num=n): | ||
_subtest(n) | ||
|
||
if xfail_msgs: | ||
pytest.xfail("; ".join(xfail_msgs)) |