import allure import pytest from frostfs_testlib.s3.aws_cli_client import AwsCliClient from frostfs_testlib.s3.boto3_client import Boto3ClientWrapper class Clients: AttributeClient = ... def parametrize_fixture() -> list[int]: return [1, 2, 3] # ============== DYNAMIC FIXTURE ============== # def pytest_generate_tests(metafunc: pytest.Metafunc): # Required dynamic fixture if "required_runtime_fixture" in metafunc.fixturenames: metafunc.parametrize("required_runtime_fixture", [AwsCliClient, Boto3ClientWrapper, Clients.AttributeClient]) # Optional dynamic fixture 1 if "optional_runtime_fixture_1" in metafunc.fixturenames: metafunc.parametrize("optional_runtime_fixture_1", [True]) # Optional dynamic fixture 2 if "optional_runtime_fixture_2" in metafunc.fixturenames: metafunc.parametrize("optional_runtime_fixture_2", [parametrize_fixture()]) # Required dynamic fixtures if "required_runtime_1" in metafunc.fixturenames and "required_runtime_2" in metafunc.fixturenames: metafunc.parametrize("required_runtime_1,required_runtime_2", [(1, 2), (3, 4)]) # Optional dynamic fixtures if "optional_runtime_1" in metafunc.fixturenames and "optional_runtime_2" in metafunc.fixturenames: metafunc.parametrize(["optional_runtime_1", "optional_runtime_2"], [("optional", [1, 2, 3])]) # Required dynamic fixture with implicit parameterization 1 if "implicitly_required_runtime_fixture_1" in metafunc.fixturenames: metafunc.parametrize("implicitly_required_runtime_fixture_1", parametrize_fixture()) # Required dynamic fixture with implicit parameterization 2 if "implicitly_required_runtime_fixture_2" in metafunc.fixturenames: metafunc.parametrize("implicitly_required_runtime_fixture_2", [*parametrize_fixture()]) # Required dynamic fixture with implicit parameterization 3 if "implicitly_required_runtime_fixture_3" in metafunc.fixturenames: metafunc.parametrize("implicitly_required_runtime_fixture_3", [0, parametrize_fixture(), *parametrize_fixture()]) @allure.title("Test required runtime fixture") def test_required_runtime_fixture(required_runtime_fixture): assert True @allure.title("Test optional runtime fixture 1") def test_optional_runtime_fixture_1(optional_runtime_fixture_1): assert True @allure.title("Test optional runtime fixture 2") def test_optional_runtime_fixture_2(optional_runtime_fixture_2): assert True @allure.title("Test required runtime fixtures") def test_required_runtime_fixtures(required_runtime_1, required_runtime_2): assert True @allure.title("Test optional runtime fixtures") def test_optional_runtime_fixtures(optional_runtime_1, optional_runtime_2): assert True @allure.title("Test implicitly required runtime fixture 1") def test_implicitly_required_runtime_fixture_1(implicitly_required_runtime_fixture_1): assert True @allure.title("Test implicitly required runtime fixture 2") def test_implicitly_required_runtime_fixture_2(implicitly_required_runtime_fixture_2): assert True @allure.title("Test implicitly required runtime fixture 3") def test_implicitly_required_runtime_fixture_3(implicitly_required_runtime_fixture_3): 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 @allure.title("Test optional fixture") def test_optional_fixture(optional_parametrized_fixture): 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