python - 我怎样才能让 pytest 忽略不子类 unittest 的 Test* 类?

标签 python pytest

我正在尝试为 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/

相关文章:

Pytest:在pytest_addoption hook中添加互斥组

python - 如何获取 Pandas 数据框中最小值之后的所有记录

gitlab - 将 pytest 覆盖率附加到 Gitlab CI 工件中的文件

python - 如何在每个测试用例中都有一个记录器?

python - 值错误 : invalid literal for int() with base 10: b'1\n5\n'

Python Mocking - 如何修补函数内的变量

assert - pytest 中的自定义断言应该覆盖标准断言

python - 使用 python 进行线性回归的简单预测

Python - 另一个编码问题。 Windows 8.1,都是最新的 python。 pip 抛出异常

python - GAE(AppEngine)似乎在发布后调整了我的图像大小