在pytest中列出未使用的fixture的简单插件
pytest-deadfixtures的Python项目详细描述
一个简单的插件,列出pytest套件中未使用或重复的fixture。
功能
- 列出测试中未使用的设备
- 列出重复的固定装置
用法
重要
–dead fixtures选项不会运行您的测试,而且对于pytest收集步骤中的错误也是合理的。 如果使用作为ci进程的一部分,建议在默认测试运行之后运行它。例如:
script: - pytest - pytest --dead-fixtures
列出未使用的装置
只需运行“pytest”和一个额外的选项“dead fixtures”:
$ pytest --dead-fixtures ============================= test session starts ============================== (hidden for brevity) Hey there, I believe the following fixture(s) are not being used: Fixture name: some_fixture, location: test_write_docs_when_verbose.py:5 ========================= no tests ran in 0.00 seconds =========================
使用一定的详细程度也会打印每个设备的docstring:
$ pytest --dead-fixtures -v ============================= test session starts ============================== (hidden for brevity) Hey there, I believe the following fixture(s) are not being used: Fixture name: some_fixture, location: test_write_docs_when_verbose.py:5 Blabla fixture docs ========================= no tests ran in 0.00 seconds =========================
列出重复的fixture
既然您删除了测试套件中所有未使用的fixture,那么如果您想多跑一英里呢?
一个重要的注意事项是,它使用fixture返回值来验证两个或多个fixture是否相等。
这意味着没有truthy返回值的fixtures将被跳过。
您应该仅将其用作提示,在删除其中一个设备之前,请确认两个设备提供的功能确实重复。
只需使用额外的选项“-dup fixtures”运行“pytest”,与“dead fixtures”选项不同,它通常会运行您的测试:
$ pytest --dup-fixtures ======================================================================================================================== test session starts ======================================================================================================================== (hidden for brevity) tests/test_deadfixtures.py ........ You may have some duplicate fixtures: Fixture name: someclass_fixture, location: test_repeated_fixtures.py:12 Fixture name: someclass_samefixture, location: test_repeated_fixtures.py:17
使用它的项目
贡献
我们非常欢迎您的贡献。测试可以用tox运行,请确保 在提交请求之前,覆盖范围至少保持不变。
许可证
“pytest deadfixtures”是根据MIT许可证的条款发布的免费开源软件
问题
如果您遇到任何问题,请file an issue连同详细说明。