Package: pytest-watcher
Welcome to pytest-watcherOverviewpytest-watcheris a tool to automatically rerun tests (usingpytestby default) whenever your code changes.Works on Unix (Linux, MacOS, BSD) and Windows.Example:Table of contentsMotivationFile EventsInstallationUsageUsing a different test runnerWatching different patternsDelayDifferences with pytest-watchConfiguringCompatibilityLicenseMotivationWhy not general toolsEasy to use and rememberWorks for most Python projects out of the boxUses native system monitoring API instead of polling on supported systems (seewatchdog documentation)Listens for new file, delete file, change and move eventsRuns your tests with latest changes in case of post-processing events (seedelay)Has an interactive mode with handy keyboard shortcuts (Currently only available on POSIX systems)What about pytest-watchpytest-watchhas been around for a long time and used to address exactly this problem. Unfortunately, pytest-watch is no longer maintained and doesn't work for many users. This project provides an alternative for it.See also:Differences with pytest-watchFile eventsBy defaultpytest-watcherlooks for the following events:New*.pyfile createdExisting*.pyfile modifiedExisting*.pyfile deletedA*.pyfile moved either from or to the watched pathYou can specify alternative file patterns to watch. SeeWatching different patternsInstallationpipinstallpytest-watcherUsageSpecify the path that you want to watch:ptw.orptw/home/repos/projectpytest-watcherwill pass any arguments after<path>to the test runner (which ispytestby default). For example:ptw.-x--lf--nfwill callpytestwith the following arguments:pytest-x--lf--nfUsing a different test runnerYou can specify an alternative test runner using the--runnerflag:ptw.--runnertoxWatching different patternsYou can use the--patternsflag to specify file patterns that you want to watch. 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 alsoignorecertain patterns using the--ignore-patternsflag:ptw.--ignore-patterns'settings.py,db.py'Delaypytest-watcheruses 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 (for example,blackplugin in your IDE). This ensures that tests will run with the latest version of your code.You can control the actual delay value with the--delayflag:ptw.--delay0.2To disable the delay altogether, you can set zero as a value:ptw.--delay0Screen clearingUse the--clearflag to clear the terminal screen before each test runptw.--clearDifferences withpytest-watchEven though this project was inspired bypytest-watch, it's not a fork of it. Therefore, there aredifferencesin behavior:pytest-watcherneeds you to specify a path to watch as a first argument:ptw.pytest-watcherdoesn't start tests immediately by default. You can customize this behavior using--nowflag.ConfiguringYou can configurepytest-watcherviapyproject.tomlfile. Here is the default configuration:[tool.pytest-watcher]now=falseclear=truedelay=0.2runner="pytest"runner_args=[]patterns=["*.py"]ignore_patterns=[]CompatibilityThe code is compatible with Python versions 3.7+LicenseThis project is licensed under theMIT License.