STUB包装、模块和属性。
pytest-stub的Python项目详细描述
https://github.com/idlesign/pytest-stub
说明
存根包、模块和属性。
这个pytest插件允许您用存根替换依赖项。
如果您想使用依赖项来测试某些代码,而不是实际拥有此依赖项,那么它可能非常有用, 例如,如果您正在测试库,它将使用另一个库的某些部分。
要求
- Python3
- Pytest=2.9.0
如何使用
在测试函数中使用stubfixture,如下所示:
deftest_django_related(stub):stub.apply({# Replace `call_command` with a generated function.'django.core.management.call_command':'[func]',# Replace `BaseCommand` with a generated class.'django.core.management.base.BaseCommand':'[cls]',# Stub multiple attributes in the same module with custom objects.'django.conf':{'settings':object(),'some':True,},})
您可以用自己的自定义对象存根依赖关系,也可以指示pytest-stub 为您生成函数或类。