Skip to content

Commit

Permalink
feat(tests): add subtests to framework tests as an example
Browse files Browse the repository at this point in the history
Added a new test class `TestSubtests` to verify outcomes using subtests.
  • Loading branch information
mkoura committed Sep 25, 2024
1 parent 1cee398 commit 6d515dc
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions framework_tests/test_subtests.py
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))

0 comments on commit 6d515dc

Please sign in to comment.