是否可以使用unit2运行文档测试
我最近从鼻子切换到新的unittest2包来满足我的Python单元测试需求。它做了我想做的一切,除了我无法得到它的“发现”命令来识别我的代码中的文档测试 - 我仍然必须使用鼻子来运行它们。这是没有实现还是我在这里遗漏了什么?
I recently switched from nose to the new unittest2 package for my python unit testing needs. It does everything I want, except from the fact that I can't get its "discover" command to recognize the doctests in my code - I still have to use nose to run them. Is this not implemented or is there something I'm missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Unit2 仅发现常规 Python 测试。为了让它运行您的文档测试,恐怕您需要编写一些最小的样板文件。另外:即将推出的插件架构将使其中一些任务的自动化变得容易。
同时。你可能想看看tox(由unittest2创建者在此处描述)http: //www.voidspace.org.uk/python/weblog/arch_d7_2010_07_10.shtml
Unit2 only discovers regular Python tests. In order to have it run your doctests, I'm afraid you would need to write some minimal boilerplate. Also: the upcoming plugin architecture will make it easy to automate some of these tasks.
In the meantime. you might want to take a look at tox (described here by unittest2 creator) http://www.voidspace.org.uk/python/weblog/arch_d7_2010_07_10.shtml
告诉unit2你的doctests所需的样板实际上在当前的doctest文档中给出,尽管我花了几分钟才找到它:
http://docs.python.org/library/doctest.html#unittest-api
请注意,您可以将模块名称传递给
DocTestSuite
构造函数,而不必自己导入模块,这可以将样板文件的长度减少一半;它只需要看起来像:The boilerplate needed to tell unit2 about your doctests is actually given in the current doctest documentation, though it took me a few minutes to find it:
http://docs.python.org/library/doctest.html#unittest-api
Note that you can pass module names to the
DocTestSuite
constructor instead of having to import the module yourself, which can cut the length of your boilerplate file in half; it just needs to look like: