带有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
    

    使用Console 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

备选方案

  • xdist提供 --looponfail-f)选项(和分布式测试选项)。 相反,它只重新运行那些失败的测试,直到您 让他们过去。这是一个速度优势 测试通过,但没有发现新的失败,直到 那么。它还会删除py.test输出的颜色,而 Pytest手表没有。
  • Nosey是原始代码基 这是用叉子叉的。不修边幅的跑步 nose而不是pytest。

贡献

  1. 检查打开的问题或打开新问题以开始讨论 围绕您的功能理念或您发现的错误
  2. 分叉存储库,进行更改,并将自己添加到 Authors.md
  3. 发送拉取请求

如果要编辑自述文件,请确保对 README.md并运行以下命令重新生成README.rst 文件:

$ pandoc -t rst -o README.rst README.md

如果您的公关已经等了一段时间,请随时ping me on Twitter

经常使用这个软件?:笑脸:

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用Jackson生成所需的JSON响应   使用XMLStreamWriter将java附加到XML   java找不到适用于addAll的方法(List<Integer>)   java如何保存以前在GridLayout上单击过的组件的位置   如何从其他类修改arraylist?JAVA   java Spring引导和GCP连接云SQL实例和springcloudgcpstartersqlpostgresql尝试SSL,但延迟启动   javascript为什么Java无限循环是可能的?对此有什么建议   java如何更改书写器的颜色。普林顿   LinkedBlockingQueue的java内部工作   Java方法从未到达(?)大体上   java Android地图视图未加载内容   正则表达式Java条件   java如何在Javadoc中格式化包含@和{符号的代码段?   excel用Java从Office和PDF文件中提取文本   java音乐无法在可执行文件中播放。Jar文件   java为什么视图没有更新?   googleoauthjavaclient因twitch而失败   java加载纹理LWJGL