pytest-integration is a plugin for pytest that allows users to organize tests into 'unit', 'integration', and 'slow integration' categories. It ensures that integration tests run only after unit tests, and slow integration tests run after quick integration tests, stopping execution of later stages if earlier ones fail. When `pytest-cov` is installed, it automatically disables code coverage for integration tests, assuming unit tests handle comprehensive coverage. The current version is 0.2.3, last released on November 17, 2022, suggesting a low-activity or stable maintenance phase.
pip install pytest-integrationVerified import paths — ran on the pinned version, not inferred.
Define tests with `@pytest.mark.integration_test` or `@pytest.mark.slow_integration_test`. Run pytest with `--with-integration` to include quick integration tests and `--with-slow-integration` to include slow integration tests. Unit tests run by default. If a unit test fails, integration tests are skipped. If an integration test fails, slow integration tests are skipped.
Be aware of `xdist` behavior. If strict sequential execution across *all* tests (not just within a single node's collected tests) is critical, consider running without `xdist` or designing tests to be fully isolated.
To include integration tests in coverage reporting, use the `--integration-cover` command-line option when running pytest. Example: `pytest --with-integration --integration-cover`.
Always invoke pytest directly (e.g., `pytest` or `python -m pytest`) rather than through `setup.py`. Refer to `pytest-runner` notice and `pypa/setuptools#1684` for more details and migration instructions.