pytest-skip-slow
pytest-skip-slow is a pytest plugin that enhances test execution by allowing users to mark tests as 'slow'. By default, tests marked with `@pytest.mark.slow` are skipped, helping maintain a fast local development feedback loop. These slow tests can then be explicitly included using the `--slow` command-line option. The current version is 0.0.5, released in February 2023, indicating a mature but infrequently updated project.
Common errors
-
pytest: error: unrecognized arguments: --slow
cause The `pytest-skip-slow` plugin is either not installed, or pytest is not detecting it correctly in your environment.fixEnsure `pytest-skip-slow` is installed in your active Python environment: `pip install pytest-skip-slow`. -
=========================== 0 passed, 1 skipped in 0.XXs =========================== (when expecting slow tests to run)
cause Tests marked with `@pytest.mark.slow` are being skipped by default, which is the intended behavior of the plugin when the `--slow` flag is not present.fixTo include and run these tests, execute `pytest --slow`. -
PytestCollectionWarning: 'slow' not found in 'markers' configuration option.
cause This is a warning from pytest itself, indicating that the `slow` marker is used but not explicitly declared in the `pytest.ini` configuration file.fixAdd `markers = slow: marks tests as slow` to the `[pytest]` section of your `pytest.ini` file to suppress this warning.
Warnings
- gotcha Running `pytest -m slow` alone will still skip tests marked with `@pytest.mark.slow` if `pytest-skip-slow` is active, as its default behavior is to skip them. To run *only* slow tests, you must explicitly include them with `--slow`.
- gotcha Pytest recommends declaring custom markers in your `pytest.ini` file to prevent `PytestUnknownMarkWarning`. While `pytest-skip-slow` provides the functionality, adding 'slow' to `markers` section in `pytest.ini` is a good practice.
Install
-
pip install pytest-skip-slow
Imports
- @pytest.mark.slow
import pytest @pytest.mark.slow def test_my_slow_function(): ...
Quickstart
import pytest
import time
def test_fast_calculation():
assert 1 + 1 == 2
@pytest.mark.slow
def test_long_running_process():
time.sleep(2) # Simulate a slow operation
assert True
# To run fast tests (skipping slow by default):
# $ pytest
# To include slow tests:
# $ pytest --slow
# To run ONLY slow tests:
# $ pytest -m slow --slow