pytest-watcher
pytest-watcher is a command-line interface (CLI) tool that automatically reruns your Python tests (using pytest by default) whenever your code changes. It is a maintained alternative to the unmaintained `pytest-watch` and is designed to streamline the test-driven development (TDD) workflow by providing continuous test feedback. The current version is 0.6.3, and it supports Unix (Linux, MacOS, BSD) and Windows.
Warnings
- breaking pytest-watcher is a modern, maintained alternative to the older, unmaintained `pytest-watch` (also known as `ptw`). If you were using `pytest-watch`, be aware that it had known issues (e.g., with `pyproject.toml` parsing) which `pytest-watcher` aims to resolve. Migrate to `pytest-watcher` for ongoing support and compatibility.
- gotcha Arguments passed to `ptw` are either consumed by `pytest-watcher` itself or forwarded to the underlying test runner (pytest by default). Ensure you understand which arguments are reserved by `pytest-watcher` (e.g., `--runner`, `--patterns`, `--ignore-patterns`, `--delay`, `--clear`, `--now`, `--notify-on-failure`) and which will be passed to `pytest` (typically all arguments after a directory path or a `--` separator).
- gotcha pytest-watcher introduces a short default delay (0.2 seconds) before triggering a test run after a file change. This is intentional to debounce rapid saves (e.g., by IDE formatters) and allow post-processors to complete. If you require immediate test execution, this delay might be unexpected.
Install
-
pip install pytest-watcher
Imports
- ptw
Run from command line: ptw .
Quickstart
# In your project directory with pytest tests: # Create a dummy test file (e.g., test_example.py) # def test_addition(): # assert 1 + 1 == 2 # Run the watcher ptw .