Framework Mode - pytest-xdist installation
Folder Structure for pytest with xdist
project-root/ ├── tests/ │ ├── test_example.py │ └── test_another.py ├── conftest.py ├── pytest.ini └── requirements.txt
project-root/ ├── tests/ │ ├── test_example.py │ └── test_another.py ├── conftest.py ├── pytest.ini └── requirements.txt
tests/ folder containing test functions.conftest.py to prepare test environment.pytest.ini to configure pytest options including xdist settings.requirements.txt including pytest and pytest-xdist.To install and configure pytest-xdist for parallel test execution:
pytest-xdist to requirements.txt or install via pip:pip install pytest-xdist
pytest.ini to include any options if needed (optional):[pytest] addopts = -n auto
-n option to specify number of parallel workers when running tests:pytest -n 4
pytest-xdist focuses on parallel execution.pytest-xdist runs tests in parallel but integrates seamlessly with pytest reporting.
pytest-html for HTML reports compatible with xdist.pytest-xdist and run tests with pytest -n auto to speed up test execution.scope="function" or scope="session" carefully to avoid shared state issues.pytest.ini to set default parallelism with addopts = -n auto for convenience.pytest-xdist with other plugins like pytest-rerunfailures for robust test runs.Where in this folder structure would you add a new fixture to prepare a database connection for tests running in parallel?