Automatically rerun your tests on file modifications
Project description
A simple watcher for pytest
Overview
pytest-watcher is a tool to automatically rerun tests (using pytest
by default) whenever your code changes.
Works on Unix (Linux, MacOS, BSD) and Windows.
Table of Contents
- Motivation
- File Events
- Installation
- Usage
- Using a different test runner
- Watching different patterns
- Delay
- Compatibility
- License
Motivation
Why not general tools (e.g. watchmedo
, entr
)?
- Easy to use and remember
- Works for most python projects out of the box
- Minimum dependencies (
watchdog
is the only one) - Handles post-processing properly (see delay)
What about pytest-watch?
pytest-watch has been around for a long time and used to address exactly this problem. Unfortunately, pytest-watch is no longer maintained and does not work for many users. To provide a substitute, I developed this tool.
File events
By default pytest-watcher
looks for the following events:
- New
*.py
file created - Existing
*.py
file modified - Existing
*.py
file deleted - A
*.py
file moved either from or to the watched path
You can specify alternative file patterns to watch. See Watching different patterns
Installation
pip install pytest-watcher
Usage
Specify the path that you want to monitor:
ptw .
or
ptw /home/repos/project
Any arguments after <path>
will be passed to the test runner (which is pytest
by default). For example:
ptw . -x --lf --nf
will call pytest
with the following arguments:
pytest -x --lf --nf
Using a different test runner
You can specify an alternative test runner using the --runner
flag:
ptw . --runner tox
Watching different patterns
You can use the --patterns
flag to specify file patterns that you want to monitor. It accepts a list of Unix-style patterns separated by a comma. The default value is "*.py".
Example:
ptw . --patterns '*.py,pyproject.toml'
You can also ignore certain patterns using the --ignore-patterns
flag:
ptw . --ignore-patterns 'settings.py,db.py'
Delay
pytest-watcher
uses a short delay (0.2 seconds by default) before triggering the actual test run. The main motivation for this is post-processors that can run after you save the file (e.g., black
plugin in your IDE). This ensures that tests will be run with the latest version of your code.
You can control the actual delay value with the --delay
flag:
ptw . --delay 0.2
To disable the delay altogether, you can provide zero as a value:
ptw . --delay 0
Compatibility
The code is tested for Python versions 3.7+
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytest_watcher-0.3.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b93e20b3e8e9cedb6ccfe974e618b395daaef358be13f78688a6da6bd0117c5 |
|
MD5 | 27c1227a49a5c3521f5e0de17a9dcb9b |
|
BLAKE2b-256 | 23201ebdebbbd8adf042ea22df8e614534a7be6743a51eea6cf412b352f48a2e |