过滤基于unittest的测试类的pytest插件
pytest-unittest-filter的Python项目详细描述
pytest unittest过滤器
用于筛选基于unittest的测试类的pytest插件
说明
pytest
具有基于unittest
的测试support out of the box。它简化了对现有项目从遗留测试套件到^ {CD1> }的增量转换,但它有一个缺点:无法排除从集合中排除的一些测试用例(^ {CD4}}子类)。pytest
具有python_classes
config option,但是,如文档中所述,此选项不影响unittest.TestCase
子类:
Note that unittest.TestCase derived classes are always collected regardless of this option, as unittest‘s own collection framework is used to collect those tests.
对于使用内置unittest
测试运行程序(python -m unittest
)的项目来说,这可能是正常的,因为后者也没有任何包含/排除选项,但是如果项目测试套件与nose
测试运行程序一起使用,并且依赖于hard-coded前导下划线筛选器,则可能不方便。
插件提供了两个新的配置选项:python_unittest_classes
和python_unittest_exclude_underscore
。
python_unittest_classes
此选项的工作方式与上面提到的python_classes
选项类似,但对于unittest.TestCase
子类:
One or more name prefixes or glob-style patterns determining which classes are considered for test collection. Search for multiple glob patterns by adding a space between patterns.
默认值为none(无值),即默认收集所有unittest.TestCase
子类。
示例
仅包含名称以
Test
或Check
开头的类:[pytest]python_unittest_classes=Test* Check*
或者:
[pytest]python_unittest_classes=Test Check
仅包含名称以
TestCase
结尾的类:[pytest]python_unittest_classes=*TestCase
排除名称以下划线开头的类:
[pytest]python_unittest_classes=[!_]*
python_unittest_exclude_underscore
此布尔选项可用于模拟hard-coded鼻子选择器行为。如果选项设置为true
,则将排除名称以_
开头的所有类。因此,上面的最后一个示例可以重写如下:
[pytest]python_unittest_exclude_underscore=true
默认值是false
。
两个选项都可以组合。以下两个示例是等效的:
[pytest]python_unittest_classes=[!_]*Test [!_]*Check
[pytest]python_unittest_classes=*Test *Checkpython_unittest_exclude_underscore=true
更改日志
0.2.1(2019-01-12)
- 修复了将
python_unittest_exclude_underscore
应用于任何收集的项而不仅仅是unittest类的错误
0.2.0(2019-01-11)
- 添加了
python_unittest_exclude_underscore
选项
0.1.0(2018-10-27)
- 初始版本