import allure import pytest # ============== DYNAMIC FIXTURE ============== # def pytest_generate_tests(metafunc: pytest.Metafunc): if "runtime_fixture" not in metafunc.fixturenames: return metafunc.parametrize("runtime_fixture", [1, 2, 3]) @allure.title("Test runtime fixture") def test_runtime_fixture(runtime_fixture): assert True # ============== IGNORE ============== # @allure.title("Ignored test") @pytest.mark.parametrize("param_in_ignored_test", [1, 2, 3]) def test_ignored(param_in_ignored_test): # noqa: allure-validator assert True # ============== EMPTY TITLE ============== # def test_empty_title_1(): assert True # @allure.title() - even pytest complains about this def test_empty_title_2(): assert True @allure.title("") def test_empty_title_3(): assert True # ============== NOT UNIQUE ============== # @allure.title("Not unique test") def test_not_unique_1(): assert True @allure.title("Not unique test") def test_not_unique_2(object_fixture): assert True @allure.title("Test title") def test_title_not_unique_1(): assert True @allure.title("Test title") def test_title_not_unique_2(): assert True # ============== MISSING PARAMS ============== # @allure.title("Test: match (p1={p1}, p2={p2})") # One required, other optional @pytest.mark.parametrize(["p1", "p2"], [[1, 2], [3, 4]]) def test_multi_params(p1, p2): assert True @allure.title("Test: match (p1={p1})") # One required, other optional @pytest.mark.parametrize("p1, p2, p3", [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) def test_str_params(p1, p2, p3): assert True @allure.title("Test: 1 (param_one={param_one}, param_two={param_two}, obj_size={object_size.value})") @pytest.mark.parametrize("param_one", [1, 2]) # Required @pytest.mark.parametrize("param_two", [3, 4]) # Required def test_one(param_one: int, param_two: int, object_fixture: str): assert True @allure.title("Test: 2 (param_one={param_one}, param_three={param_three}, obj_size={object_size})") @pytest.mark.parametrize("param_one", [1, 2]) # Required @pytest.mark.parametrize( ["param_two", "param_three"], # One required, other optional [ [3, 4], [5, 6], ], ) def test_two(param_one: int, param_two: list, param_three: list, object_fixture: str): assert True @allure.title("Test: 3 (obj_size={object_size})") # Required, object_size is parametrized def test_three(object_fixture: str): assert True @allure.title("Test: 3 indirect=True") # Optional, len(params) == 1 @pytest.mark.parametrize("object_size", ["complex"], indirect=True) def test_three_indirect_true(object_fixture: str): assert True @allure.title("Test: 3 multiple indirect (obj_size={object_size})") # Required, len(params) != 1 @pytest.mark.parametrize("object_size", ["single", "complex"], indirect=True) def test_three_multiple_indirect(object_fixture: str): assert True # ============== TESTS/FIXTURES IN CLASS ============== # @pytest.mark.parametrize("param_class_1", [1, 2]) # Required @pytest.mark.parametrize("param_class_2", [3]) # Optional class TestClassParam: @pytest.fixture( params=[ pytest.param(6), pytest.param(7), ] ) def root_fixture(self): return 1 @pytest.fixture def dependency_fixture(self, root_fixture): return root_fixture + 1 @pytest.fixture(scope="function") # Optional fixture def object_fixture(self, simple_object_size): return simple_object_size @allure.title("Test: 4 (param_class_1={param_class_1})") # One required, other optional def test_four(self, param_class_1: int, param_class_2: int, object_fixture): assert True @allure.title("Test: 5 (param_class_1={param_class_1}, param_class_2={param_class_2}, param_five={param_five}") @pytest.mark.parametrize("param_five", [4, 5]) # Required def test_five(self, param_five, param_class_1, param_class_2, dependency_fixture): assert True @allure.title("Not unique test (param_class_1={param_class_1})") # One required, other optional def test_not_unique_3(self, param_class_1, param_class_2): assert True @pytest.fixture(scope="function") # Required fixture def object_fixture(file_path): return file_path @pytest.fixture # Optional fixture def dependency_fixture(): return 1