过滤基于unittest的测试类的pytest插件

pytest-unittest-filter的Python项目详细描述


pytest unittest过滤器

Build StatusPyPI

用于筛选基于unittest的测试类的pytest插件

说明

pytest具有基于unittest的测试support out of the box。它简化了对现有项目从遗留测试套件到^ {CD1> }的增量转换,但它有一个缺点:无法排除从集合中排除的一些测试用例(^ {CD4}}子类)。pytest具有python_classesconfig 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_classespython_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子类。

示例

  • 仅包含名称以TestCheck开头的类:

    [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)

  • 初始版本

许可证

MIT License

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在IE10中重新加载另一个帧时,internet explorer Java小程序失败/消失   ThreadLocal变量的java性能   java系统。出来println不是打印输出   java从JAXB类获取元素属性   java组织。天啊。科尔巴。包裹。InvalidName:IDL:omg。org/CORBA/ORB/InvalidName:1.0   java有没有办法让非事务连接抛出异常?   java是否有任何方法可以使用JdbcTemplate和查询/条件Fluent API   javajpa级联类型。刷新不工作?   未考虑java Maven依赖关系管理   java MySQL MBR包含抛出MySQLExceptionError的语句   java验证整数并将其设为5位数   java发现了循环依赖的问题   java Hibernate left join fetch到使用@ManyToMany关联映射的softdeleted实体生成无效查询?   JavaH:commandButton多个操作:下载文件并呈现ajax表   Google Contacts API在Java、C#、Python或Ruby中是否有一个Hello World示例?