pytest-fail-slow
raw JSON → 0.6.0 verified Mon Apr 27 auth: no python
A pytest plugin that fails tests exceeding a configurable duration. v0.6.0 supports both marker-level and command-line slow time thresholds; actively maintained.
pip install pytest-fail-slow Common errors
error ImportError: cannot import name 'fail_slow' from 'pytest_fail_slow' ↓
cause Older versions may not expose the decorator; or package not installed.
fix
Install pytest-fail-slow >=0.5.0: pip install --upgrade pytest-fail-slow
error TypeError: fail_slow() missing 1 required positional argument: 'seconds' ↓
cause Decorator called without parentheses or argument.
fix
Use @fail_slow(2.0) not @fail_slow
error pytest: error: unrecognized arguments: --fail-slow ↓
cause Using deprecated flag; plugin expects new flag.
fix
Use
--fail-slow-seconds <value> instead. Warnings
gotcha The @fail_slow decorator must be applied after @pytest.mark.slow or similar markers; order matters because the decorator reads the test's current marker info. ↓
fix Place @fail_slow closest to the function, above other custom decorators.
gotcha The plugin only works with pytest's default runner; custom runners may silently ignore the fail_slow marker. ↓
fix Use the default pytest runner.
deprecated The CLI option --fail-slow is deprecated in v0.6.0; use --fail-slow-seconds instead. ↓
fix Use `--fail-slow-seconds <seconds>` from command line.
Imports
- fail_slow
from pytest_fail_slow import fail_slow
Quickstart
# conftest.py
pytest_plugins = ['pytest_fail_slow']
# then in test
import pytest
from pytest_fail_slow import fail_slow
@fail_slow(0.5)
def test_fast_enough():
import time
time.sleep(0.1)
assert True