Framework Mode - Running with -n auto
Folder Structure
project-root/ ├── tests/ │ ├── test_example.py │ ├── test_login.py │ └── test_api.py ├── conftest.py ├── pytest.ini └── requirements.txt
project-root/ ├── tests/ │ ├── test_example.py │ ├── test_login.py │ └── test_api.py ├── conftest.py ├── pytest.ini └── requirements.txt
tests/ folder, contain test functions using pytest syntax.conftest.py to provide setup and teardown for tests.pytest.ini holds pytest settings and options.pytest-xdist plugin, enabling tests to run in parallel.To run tests in parallel automatically based on CPU cores, use the -n auto option from the pytest-xdist plugin.
Example command to run tests in parallel:
pytest -n auto
Configuration can also be added to pytest.ini for convenience:
[pytest] addopts = -n auto
This runs tests using as many workers as CPU cores detected, speeding up test execution without manual tuning.
pytest -n auto in pipeline scripts.pytest-html or pytest-junitxml to generate detailed reports.pytest-xdist for parallel test execution.-n auto to automatically match CPU cores, avoiding overload.Question: Where in this framework structure would you add a new fixture that sets up a database connection to be used by tests running in parallel?