我正在尝试为 testfixtures 进行测试通过 pytest,但它一直试图收集不是测试的东西:
======================================================= 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* 类?
最佳答案
我在 Pytest 中找到了这个 2.6 release notes :
support nose-style
__test__
attribute on modules, classes and functions, including unittest-style Classes. If set to False, the test will not be collected.
如果您的类 在您不希望被收集时被收集,这会有所帮助,但它对“无法收集测试类因为它有一个 __init__
构造函数”警告。
关于python - 我怎样才能让 pytest 忽略不子类 unittest 的 Test* 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42268401/