From 6d515dc214c80a60ffdc7242ee72c193495619c0 Mon Sep 17 00:00:00 2001 From: Martin Kourim Date: Wed, 25 Sep 2024 14:58:03 +0200 Subject: [PATCH] feat(tests): add subtests to framework tests as an example Added a new test class `TestSubtests` to verify outcomes using subtests. --- framework_tests/test_subtests.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 framework_tests/test_subtests.py diff --git a/framework_tests/test_subtests.py b/framework_tests/test_subtests.py new file mode 100644 index 000000000..cb4d43b49 --- /dev/null +++ b/framework_tests/test_subtests.py @@ -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))