[英]Anyone know how nosetest's -m, -i and -e work?
I am trying to get nosetests to identify my tests but it is not running any of my tests properly. 我试图通过鼻子测试来识别我的测试,但它没有正确运行我的任何测试。
I have the following file structure 我有以下文件结构
Project
+----Foo/
+----__init__.py
+----bar.py
+----test/
+----__init__.py
+----unit/
+----__init__.py
+----bar_test.py
+----functional/
+----__init__.py
+----foo_test.py
Within bar_test.py 在bar_test.py内
class BarTest(unittest.TestCase):
def bar_1_test():
...
Within foo_test.py 在foo_test.py中
class FooFTest.py
def foo_1_test():
...
Using -m, -i, -e options of nosetests 使用-m,-i,-e nosetests选项
I've tried various combinations and can't seem to get nosetests to do what I want consistently 我已经尝试了各种组合,似乎无法通过鼻子测试来做我想要的一贯
The easiest way to run only the tests under Project/test/unit
is to use --where
. 仅在Project/test/unit
下运行测试的最简单方法是使用--where
。 For example: 例如:
nosetests --where=Project/test/unit
Then use --match
( -m
) or --exclude
( -e
) to refine the list, if needed. 然后使用--match
( -m
)或--exclude
( -e
)来细化列表(如果需要)。
If you still want to use the regex selectors, you can probably do it like this (not tested): 如果您仍想使用正则表达式选择器,您可以这样做(未经测试):
nosetests --match='^Foo[\b_\./-])[Tt]est'
Executing this script from the Project
directory would run all tests that start with "Foo" and end in "[Tt]est". 从Project
目录执行此脚本将运行以“Foo”开头并以“[Tt] \\ test”结尾的所有测试。
As a general rule, you probably want to use either --match
or --exclude
, but not both. 作为一般规则,您可能希望使用--match
或--exclude
,但不能同时使用两者。 These parameters both specify the pattern of the function names to match. 这些参数都指定要匹配的函数名称的模式。 You can refine either one by using --ignore-files
which, naturally, allows you to ignore whole files. 您可以使用--ignore-files
来优化任何一个--ignore-files
,这当然可以让您忽略整个文件。
Given your directory structure, you can easily run segments of the tests using the --exclude option. 根据您的目录结构,您可以使用--exclude选项轻松运行测试的各个部分。
Run all tests: 运行所有测试:
nosetests Project
Run unit tests: 运行单元测试:
nosetests Project -e functional
Run functional tests: 运行功能测试:
nosetests Project -e unit
If you have more complex test execution needs, I'd recommend marking the tests and using the attrib package . 如果您有更复杂的测试执行需求,我建议标记测试并使用attrib包 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.