allure-validator/tests/conftest.py
Kirill Sosnovskikh d050a94272 Fix determination of fixture parameters
- Added ability to pass any parameters to `params` keyword in `pytest.fixture`, except:
  1) `params=<callable object>`, but `params=[<callable object>, ...]` is allowed
  2) `params=[*<any collection>]`

- Analysis of `pytest_generate_tests` is almost equivalent to regular fixtures, except:
  1) `metafunc.parametrize(*<any collection>, **<any dict>)`
  2) `metafunc.parametrize("any", <callable object>)`
  3) `metafunc.parametrize("any1, any2", [(<callable object>, [*<any collection>])]`

Signed-off-by: Kirill Sosnovskikh <k.sosnovskikh@yadro.com>
2024-11-15 16:08:24 +03:00

49 lines
994 B
Python

import allure
import pytest
def parametrize_fixture() -> list[int]:
return [1, 2, 3]
@pytest.fixture(
scope="function",
params=[
pytest.param(1),
pytest.param(2),
],
)
def object_size(request: pytest.FixtureRequest):
return request.param
@pytest.fixture
def file_path(object_size):
return 0
@allure.title("[Function] Object fixture")
@pytest.fixture(scope="function")
def object_fixture(file_path):
return file_path
@allure.title("[Session] Parametrized fixture")
@pytest.fixture(
scope="session",
params=[
pytest.param(1, marks=[pytest.mark.test_1]),
pytest.param(2, marks=[pytest.mark.test_2]),
],
)
def parametrized_fixture(request: pytest.FixtureRequest):
return request.param
@allure.title("[Session] Optional parametrized fixture")
@pytest.fixture(
scope="session",
params=[parametrize_fixture()],
)
def optional_parametrized_fixture(request: pytest.FixtureRequest):
return request.param