Package: pytest-file-watcher
Py Test WatchPytest-File-Watcher is a tool that watches your files and runs your pytest tests automatically when it detects changes.Why?I was tired of runningpytestmanually every time I made a change to my code. I wanted a tool that would watch my files and run my tests automatically when it detected changes.Whilepytest-watchis a great tool, it is simply not maintained anymore. It works for most things, but I wanted something simpler. I wanted to be able to create config files within my projects so I dont need to remember all the flags and commands I need to pass to pytest. That way I just need to runpytest-w testand it will do all the work for me.Pytest-File-Watcher may not have all the features of pytest-watch (yet), but I plan to expand the functionality of this tool as needed.You will find that Pytest-File-Watcher is quite opinionated. It is designed to work with my workflow. If you have any suggestions, please feel free to open an issue or a pull request. I am always open to suggestions.I hope it helps someone else with managing a multi-project testing workflow.DisclaimerThis tool is still in development. It's not perfect by any means. It does what I need it to do, but it may not work for your use case. Please feel free to open an issue or a pull request if you find any bugs or have any suggestions. I only tested so many use cases, so I am sure there are many more that I have not thought of.InstallationpipinstallPytest-File-WatcherUsageMain entrypointpytest-wYou can run the--helpcommand to see all available options.pytest-w--helpor on any command.pytest-wtest--helpYou can also view the--versionof the tool.pytest-w--versionTest WatchingI strongly recommend using theconfig.yamlfile to configure Pytest-File-Watcher. You can use theconfigurecommand to generate aconfig.yaml(see#Config) file in the root of your project or if you prefer writing it yourself see#Config (Advanced)section. As mentioned before this is quite opinionated. I personally do not like to pass many flags and commands when testing. Especially when those flags don't change, but it can be problematic to navigate a long line of shell command to edit something. Henceuse the config.Anyway... Thetestcommand is the real reason you are here. It will watch your files and run your tests automatically when it detects changes. You need to pass the path to the folder you want to watch. You can just pass./to watch all files in the current directory.pytest-wtest./path/to/folderTest FlagsThere are many flags supported by Pytest-File-Watcher. You can pass them when using thetestcommand. These flags take priority over theconfig.yamlfile if used.The flags are quite self-explanatory. I will list them here for convenience.Verbose:-vor--verbose. Used when you want to see the full pytest output.Note:If you want a more verbose pytest output use the-pflag instead.pytest-wtest./path/to/folder-vAuto Clear:-aor--auto-clear. Used when you want to clear the terminal after each test run.pytest-wtest./path/to/folder-cConfig:-cor--config. Used when you want to pass a custom config file.pytest-wtest./path/to/folder-c"path/to/config.yaml"Ignore:-ior--ignore. Used when you want to ignore certain folders.pytest-wtest./path/to/folder-i"venv"-i"node_modules"Extensions:-eor--extensions. Used when you want to watch for extra file extensions.pytest-wtest./path/to/folder-e".py"-e".txt"Passthrough:-por--passthrough. Used when you want to pass extra flags to pytest.pytest-wtest./path/to/folder-t"-k"-t"test_something"On Pass:--on-pass. Used when you want to run a shell command when all tests pass.pytest-wtest./path/to/folder-p"echo 'All tests passed'"On Fail:--on-fail. Used when you want to run a shell command when a test fails.pytest-wtest./path/to/folder-f"echo 'A test has failed'"ConfigIf you are not familiar with yaml files, you can use this option to generate aconfig.yamlfile in the root of your project.pytest-wconfigurecreateYou can also edit theconfig.yamlfile.pytest-wconfigureeditAnd view the current configuration.pytest-wconfigureviewAll above commands accept the--configflag to specify a custom config file. The default is the current working path.pytest-wconfigurecreate--config"path/to/config.yaml"Config (Advanced)Pytest-File-Watcher can be configured using aconfig.yamlfile in the root of your project. Example of currently supported options:verbose:boolautoClear:boolonPass:shell-commandonFail:shell-commandextensions:-string-itemignore:-string-itempassthrough:-string-item-string-itemSeeexample config.This will likely change in the future, and be expanded further. I will do my best to keep the documentation up-to-date.RecommendationMy daily driver is WSL2 within Windows 10. I have found myself running Pytest-File-Watcher in the background while doing other operations in another terminal tab and often forgetting to check the status of tests. I know that on linux you can usenotify-sendto send notifications to your desktop. Well, on WSL you can usewsl-notify-sendwhich essentially sends a notification to the Windows notification center. I have found this to be very useful and I highly recommend checking it out and using it in your own projects.I have added the following to myconfig.yamlfile:onPass:wsl-notify-send.exe --category "Pytest-File-Watcher" "All tests passed"onFail:wsl-notify-send.exe --category "Pytest-File-Watcher" "A test has failed"Now I can forget about Pytest-File-Watcher and it will notify me when it is done running tests. Not sure how this will work on other platforms, but I am sure there is a similar tool for MacOS.Manual BuildIf you want to build the project manually, you can do so by cloning the repository. I recommend using a virtual environment.python-mvenvvenvsourcevenv/bin/activateThen install the dependencies.pipinstall-rrequirements.txtAnd finally build the project.pipinstall-e.Then you can run the tool whenever you are in that virtual environment.ContributingContributions are welcome! Please feel free to open an issue or a pull request.Acknowledgementspytest-watchwatchfilestyperAuthorDeviljin112LicenseMIT