我现在已经想知道这一段时间了,但是我无法弄清楚如何将选项传递给nosetests
以运行位于不同子目录中的不同测试。包目录结构示例:
my_package/
|-- my_module1/
|-- tests/
|-- unit/
| ... a bunch of unit tests
|-- integration/
|... a bunch of integration tests
|-- my_module2/
|-- tests/
|-- unit/
| ... a bunch of unit tests
|-- integration/
|... a bunch of integration tests
如果我只想在所有模块中执行单元测试(tests/unit/
子目录中的所有测试),我将如何使用nosetests库进行测试?
答案 0 :(得分:2)
我认为--where
或--match
nosetests参数可以帮助您:
-w WHERE, - where = WHERE 在此目录中查找测试。可以指定 多次。传递的第一个目录是 用作工作目录,代替当前 工作目录,这是默认值。其他人会 被添加到要执行的测试列表中。 [NOSE_WHERE]
-m REGEX, - match = REGEX, - testmatch = REGEX 文件,目录,函数名称和类名 考虑匹配此正则表达式 试验。默认值:(?:^ | [\ b _./-])[Tt] \ test [NOSE_TESTMATCH]
另请参阅Anyone know how nosetest's -m, -i and -e work?
但实际上,我更喜欢在根级别拥有测试目录:How to organize and run unittests and functional tests separately using nosetests