我试图通过pytest获取testfixtures的测试,但它一直试图收集不是测试的内容:
======================================================= pytest-warning summary ========================================================
WC1 /Users/chris/vcs/git/testfixtures/testfixtures/tests/test_comparison.py cannot collect test class 'TestClassA' because it has a __init__ constructor
WC1 /Users/chris/vcs/git/testfixtures/testfixtures/tests/test_components.py cannot collect test class 'TestComponents' because it has a __init__ constructor
WC1 /Users/chris/vcs/git/testfixtures/testfixtures/tests/test_datetime.py cannot collect test class 'TestTZInfo' because it has a __new__ constructor
WC1 /Users/chris/vcs/git/testfixtures/testfixtures/tests/test_datetime.py cannot collect test class 'TestTZ2Info' because it has a __new__ constructor
cannot collect test class 'TestContainer' because it has a __init__ constructor
cannot collect test class 'TestTZInfo' because it has a __new__ constructor
如何让pytest只收集子类的Test*类unittest.TestCase?在
我在Pytest 2.6 release notes中找到了这个:
如果您的类在您不希望被收集的时候被收集,这会有所帮助,但对于“cannot collect test class because a
__init__
构造函数”警告没有帮助。在Pytest使用glob样式的名称模式来收集测试,并且可以通过配置文件中的选项}自定义发现。在
python_files
、python_classes
和{我认为违约是这样的:
也许您可以通过重写以下内容将其自定义为不收集类:
^{2}$注意:这里不限于一种模式,您可以指定它们的列表。在
无论此选项如何,仍应收集继承
unittest.TestCase
的类。这是因为unittest框架本身用于收集这些测试。在相关问题 更多 >
编程相关推荐