nose collects tests automatically from python source files, directories and packages found in its working directory (which defaults to the current working directory). Any python source file, directory or package that matches the testMatch regular expression (by default: (?:\b|_)[Tt]est will be collected as a test (or source for collection of tests). In addition, all other packages found in the working directory will be examined for python source files or directories that match testMatch. Package discovery descends all the way down the tree, so package.tests and package.sub.tests and package.sub.sub2.tests will all be collected.
对于简单的发现,您可以使用
unittest
模块的内置命令行功能或者,如果您的
^{pr2}$tests
目录有一个__init__.py
,您可以这样做如果您绝对必须使用python2.6,python docs表示可以安装
unittest2
,这是python2.7中添加的新功能的一个后端口。你调用它的方式稍有不同另外,如果您还没有深入到} 。它在编写测试时需要的样板文件要少得多,并且允许您只使用内置的
unittest
测试兔子洞,我建议您去看看^{assert
。它还提供了一些其他很酷的特性,比如fixtures和参数化测试函数,这些特性也允许您减少单元测试中的代码量。在下面是Nose文档中的一个片段(因为您已经标记了
nose
)强调我的。在
您只需从项目的根目录运行所有测试用例:
相关问题 更多 >
编程相关推荐