Auto-focus plugin for pytest: run only @pytest.mark.focus tests when --auto-focus is set, otherwise run all tests.
pip install pytest-autofocusMark tests with @pytest.mark.focus:
import pytest
def test_normal():
pass
@pytest.mark.focus
def test_focused():
passRun with --auto-focus to run only focused tests (if any exist), otherwise run all tests:
pytest --auto-focusIf no tests are marked with @pytest.mark.focus, all tests run normally.
Run without --auto-focus to run all tests:
pytestUse with pytest-watcher for automatic test filtering:
ptw . -- --auto-focus- Python 3.10+
- pytest 7.0+