sas*_*ker 10 python regex unit-testing nosetests
我试图通过鼻子测试来识别我的测试,但它没有正确运行我的任何测试.
我有以下文件结构
Project
+----Foo/
+----__init__.py
+----bar.py
+----test/
+----__init__.py
+----unit/
+----__init__.py
+----bar_test.py
+----functional/
+----__init__.py
+----foo_test.py
Run Code Online (Sandbox Code Playgroud)
在bar_test.py内
class BarTest(unittest.TestCase):
def bar_1_test():
...
Run Code Online (Sandbox Code Playgroud)
在foo_test.py中
class FooFTest.py
def foo_1_test():
...
Run Code Online (Sandbox Code Playgroud)
使用-m,-i,-e nosetests选项
我已经尝试了各种组合,似乎无法通过鼻子测试来做我想要的一贯
仅运行测试的最简单方法Project/test/unit是使用--where.例如:
nosetests --where=Project/test/unit
Run Code Online (Sandbox Code Playgroud)
然后使用--match(-m)或--exclude(-e)根据需要优化列表.
如果您仍想使用正则表达式选择器,您可以这样做(未经测试):
nosetests --match='^Foo[\b_\./-])[Tt]est'
Run Code Online (Sandbox Code Playgroud)
从Project目录执行此脚本将运行以"Foo"开头并以"[Tt]\test"结尾的所有测试.
作为一般规则,您可能想要使用--match或--exclude,但不是两者都使用.这些参数都指定要匹配的函数名称的模式.你可以通过使用--ignore-files哪一个来改进,当然,你可以忽略整个文件.