我正在尝试通过pytest通过的testfixture 进行测试,但它一直在尝试收集不是测试的内容:
======================================================= 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
Run Code Online (Sandbox Code Playgroud)
我怎样才能让pytest只收集子类unittest.TestCase的Test *类?
Pytest 使用 glob 样式的名称模式来收集测试,并且可以通过配置文件中的选项python_files、python_classes和来自定义发现。python_functions
默认值是这样的:
[pytest]
python_files=test_*.py *_test.py
python_classes=Test
python_functions=test
Run Code Online (Sandbox Code Playgroud)
也许您可以通过覆盖它来自定义它不收集类:
# pytest.ini (or in tox.ini, or in setup.cfg)
[pytest] # if using setup.cfg, this section name should instead be [tool:pytest]
python_classes=NoThanks
Run Code Online (Sandbox Code Playgroud)
注意:这里不限于一种模式,您可以指定它们的列表。
unittest.TestCase无论此选项如何,仍应收集继承的类。这是因为单元测试框架本身用于收集这些测试。
| 归档时间: |
|
| 查看次数: |
2229 次 |
| 最近记录: |