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?