问题描述
我正在尝试通过 pytest 获取 testfixtures 的测试,但它一直在尝试收集东西不是测试:
I'm trying to get tests for testfixtures passing with pytest, but it keeps trying to collect things that aren't tests:
======================================================= 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 只收集子类 unittest.TestCase 的 Test* 类?
How can I get pytest to only collect Test* classes that subclass unittest.TestCase?
推荐答案
我在 Pytest 中发现了这个 2.6 发行说明:
I found this in the Pytest 2.6 release notes:
在模块、类和函数上支持鼻子样式的 __test__
属性,包括单元测试样式的类.如果设置为 False,则不会收集测试.
如果您的类在您不希望它被收集时被收集,这会有所帮助,但它无助于无法收集测试类,因为它有一个 __init__
构造函数"警告.
This can help if your class is being collected when you don't want it to be, but it doesn't help with the "cannot collect test class because it has a __init__
constructor" warning.
这篇关于我怎样才能让 pytest 忽略不继承 unittest 的 Test* 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!