带有pytest和看门狗的本地连续测试运行程序。
pytest-watch的Python项目详细描述
Current version on PyPISay Thanks!
pytest watch运行的零配置cli工具 pytest,并在 项目变更。它会在出现故障时发出蜂鸣音,并可以在 每次通过和失败的测试运行。
动机
无论您是否使用测试驱动的开发方法,运行测试 持续的工作远比等你完成工作更有效率 编程来测试代码。另外,手动运行 py.test每次您想查看是否有任何测试被破坏时 等待时间和认知开销 通知。在调试 复杂的问题或在很紧的期限内。
安装
$ pip install pytest-watch
用法
$ cd myproject
$ ptw
* Watching /path/to/myproject
注意:它也可以使用其全名“pytest watch”运行。
现在正常开发,不时检查终端 任何测试都被破坏。或者,pytest watch可以通知您 测试通过或失败时:
osx
$ ptw --onpass "say passed" --onfail "say failed"
$ ptw --onpass "growlnotify -m \"All tests passed!\""\ --onfail "growlnotify -m \"Tests failed\""
使用GrowlNotify。
windows
> ptw --onfail flash
也可以在测试运行之前运行命令,例如设定测试种子 数据库:
$ ptw --beforerun init_db.py
或者在它们完成之后,例如删除sqlite文件。注意这个脚本 接收作为参数的^ {TT1}$的退出代码。
$ ptw --afterrun cleanup_db.py
您还可以使用自定义运行程序脚本来实现完整的py.test控件:
$ ptw --runner "python custom_pytest_runner.py"
下面是一个运行py.test并打印其 退出代码:
# custom_pytest_runner.pyimportsysimportpytestprint('py.test exited with code:',pytest.main(sys.argv[1:]))
需要将目录排除在为测试而观察或收集的目录之外?
$ ptw --ignore ./deep-directory --ignore ./integration_tests
查看选项的完整列表:
$ ptw --help Usage: ptw [options] [--ignore <dir>...] [<directory>...] [-- <pytest-args>...] Options: --ignore <dir> Ignore directory from being watched and during collection (multi-allowed). --ext <exts> Comma-separated list of file extensions that can trigger a new test run when changed (default: .py). Use --ext=* to allow any file (including .pyc). --config <file> Load configuration from `file` instead of trying to locate one of the implicit configuration files. -c --clear Clear the screen before each run. -n --nobeep Do not beep on failure. -w --wait Waits for all tests to complete before re-running. Otherwise, tests are interrupted on filesystem events. --beforerun <cmd> Run arbitrary command before tests are run. --afterrun <cmd> Run arbitrary command on completion or interruption. The exit code of "py.test" is passed as an argument. --onpass <cmd> Run arbitrary command on pass. --onfail <cmd> Run arbitrary command on failure. --onexit <cmd> Run arbitrary command when exiting pytest-watch. --runner <cmd> Run a custom command instead of "py.test". --pdb Start the interactive Python debugger on errors. This also enables --wait to prevent pdb interruption. --spool <delay> Re-run after a delay (in milliseconds), allowing for more file system events to queue up (default: 200 ms). -p --poll Use polling instead of OS events (useful in VMs). -v --verbose Increase verbosity of the output. -q --quiet Decrease verbosity of the output (precedence over -v). -V --version Print version and exit. -h --help Print help and exit.
配置
cli选项可以添加到 pytest.ini file到 在你的项目中坚持他们。例如:
# pytest.ini[pytest]addopts=--maxfail=2[pytest-watch]ignore=./integration-testsnobeep=True
备选方案
贡献
- 检查打开的问题或打开新问题以开始讨论 围绕您的功能理念或您发现的错误
- 分叉存储库,进行更改,并将自己添加到 Authors.md
- 发送拉取请求
如果要编辑自述文件,请确保对 README.md并运行以下命令重新生成README.rst 文件:
$ pandoc -t rst -o README.rst README.md
如果您的公关已经等了一段时间,请随时ping me on Twitter。
经常使用这个软件?:笑脸: