Python 单元测试是否有类似“自动测试"之类的东西? [英] Is there something like 'autotest' for Python unittests?

查看:22
本文介绍了Python 单元测试是否有类似“自动测试"之类的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,测试中断或通过时会发出咆哮通知(或其他回调).这样的东西存在吗?

Basically, growl notifications (or other callbacks) when tests break or pass. Does anything like this exist?

如果没有,它应该很容易编写..最简单的方法是..

If not, it should be pretty easy to write.. Easiest way would be to..

  1. 运行 python-autotest myfile1.py myfile2.py etc.py
    • 检查要监控的文件是否已修改(可能只是已保存).
    • 在这些文件中运行任何测试.
    • 如果测试失败,但在上一次运行中通过了,则生成咆哮警报.与失败然后通过的测试相同.
    • 等待,然后重复步骤 2-5.

我可以看到的问题是测试是否在不同的文件中.简单的解决方案是在每次保存后运行所有测试..但是如果测试速度较慢,这可能比保存之间的时间更长,和/或可能会使用大量 CPU 能力等.

The problem I can see there is if the tests are in a different file. The simple solution would be to run all the tests after each save.. but with slower tests, this might take longer than the time between saves, and/or could use a lot of CPU power etc..

最好的方法是实际查看代码的哪些部分发生了变化,如果函数 abc() 发生了变化,则只运行与此交互的测试.. 虽然这会很棒,但我认为它会实施起来极其复杂?

The best way to do it would be to actually see what bits of code have changed, if function abc() has changed, only run tests that interact with this.. While this would be great, I think it'd be extremely complex to implement?

总结:

  • 是否有类似 Ruby 工具 autotest(ZenTest 包),但用于 Python 代码?
  • 如何检查脚本的两次修订之间哪些函数发生了变化?
  • 是否可以确定命令将调用哪些函数?(有点像反向回溯)
  • Is there anything like the Ruby tool autotest (part of the ZenTest package), but for Python code?
  • How do you check which functions have changed between two revisions of a script?
  • Is it possible to determine which functions a command will call? (Somewhat like a reverse traceback)

推荐答案

我发现 autonose 非常不可靠,但 嗅探器 似乎工作得很好.

I found autonose to be pretty unreliable but sniffer seems to work very well.

$ pip install sniffer
$ cd myproject

然后不是运行nosetests",而是运行:

Then instead of running "nosetests", you run:

$ sniffer

或者代替 nosetests --verbose --with-doctest,你运行:

$ sniffer -x--verbose -x--with-doctest

自述文件中所述,最好安装一个特定于平台的文件系统- 监视库,pyinotifypywin32MacFSEvents(均可通过 pip 等安装)

As described in the readme, it's a good idea to install one of the platform-specific filesystem-watching libraries, pyinotify, pywin32 or MacFSEvents (all installable via pip etc)

这篇关于Python 单元测试是否有类似“自动测试"之类的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆