Framework Mode - Combining multiple parametrize decorators
Folder Structure
project-root/
├── tests/
│ ├── test_example.py
│ ├── test_login.py
│ └── test_calculations.py
├── conftest.py
├── pytest.ini
└── utils/
└── helpers.py
project-root/
├── tests/
│ ├── test_example.py
│ ├── test_login.py
│ └── test_calculations.py
├── conftest.py
├── pytest.ini
└── utils/
└── helpers.py
@pytest.mark.parametrize decorators to run tests with multiple data sets. Multiple parametrize decorators can be stacked to combine parameters.conftest.py holds fixtures for setup and teardown, shared resources, and test data preparation.utils/helpers.py to keep tests clean and DRY.pytest.ini or tox.ini for pytest settings like markers, test paths, and command-line options.Use pytest.ini to define markers and default options. Use conftest.py to manage fixtures that provide test data or environment setup.
# pytest.ini
[pytest]
markers =
slow: marks tests as slow
parametrize: marks parameterized tests
# conftest.py
import pytest
@pytest.fixture
def sample_data():
return {"key": "value"}
For combining multiple parametrize decorators, simply stack them above the test function. Pytest runs the test for every combination of parameters.
--junitxml=report.xml to generate XML reports for CI tools.pytest-html for readable HTML reports.@pytest.mark.parametrize decorators to test all combinations of parameters clearly and efficiently.ids argument in parametrize for better report readability.Where in this framework structure would you add a new test file that uses multiple @pytest.mark.parametrize decorators to test a calculator's add and multiply functions?
@pytest.mark.parametrize decorators on a single test function?@pytest.mark.parametrize decorator adds a set of parameters to the test function.@pytest.mark.parametrize decorators for parameters x and y?@pytest.mark.parametrize decorators, one for each parameter. -> Option D@pytest.mark.parametrize('a', [1, 2])
@pytest.mark.parametrize('b', [3, 4, 5])
def test_sum(a, b):
assert a + b > 0
@pytest.mark.parametrize('x', [1, 2])
@pytest.mark.parametrize('y', 3, 4)
def test_func(x, y):
assert x != y
@pytest.mark.parametrize('y', 3, 4), which is invalid because values must be in a list or iterable.[3, 4]. Without brackets, it causes a syntax or runtime error.color and size. Colors are ['red', 'blue'], sizes are ['S', 'M', 'L']. You want to skip tests where color is 'red' and size is 'L'. How can you combine multiple @pytest.mark.parametrize decorators and skip that case?pytest.skip() to skip that test case.Pass the test and this pattern moves unknown