pytest帮助程序命名空间
pytest-helpers-namespace的Python项目详细描述
此插件不向pytest提供任何帮助程序,但是, 在pytest中提供一个helpers命名空间,使您能够注册helper 在测试中使用的conftest.py中的函数 以导入它们。
功能
- 提供可用于注册的helperspytest命名空间 helper函数,而不需要在实际测试中将它们导入到 使用它们。
要求
- 没有!
用法
考虑以下conftest.py文件:
pytest_plugins=['helpers_namespace']importpytest@pytest.helpers.registerdeffoo(bar):''' this dumb helper function will just return what you pass to it '''returnbar
现在考虑下面的测试用例:
deftest_helper_namespace():assertpytest.helpers.foo(True)isTrue
很简单吧?!
甚至可以嵌套名称空间。考虑以下conftest.py文件:
pytest_plugins=['helpers_namespace']importpytest@pytest.helpers.can.haz.registerdeffoo(bar):''' this dumb helper function will just return what you pass to it '''returnbar
现在考虑下面的测试用例:
deftest_helper_namespace():assertpytest.helpers.can.haz.foo(True)isTrue
您甚至可以向register函数传递一个名称,这将是helper函数的名称。
贡献
我们非常欢迎您的贡献。测试可以用tox运行,请确保 在提交请求之前,覆盖范围至少保持不变。
许可证
根据Apache Software License 2.0许可证的条款分发, “pytest helpers namespace”是免费的开源软件。
问题
如果您遇到任何问题,请file an issue连同详细的 描述。
更改日志
V2019.1.8
- 在处理任何conftest.py文件之前修补pytest。
V2019.1.7
- 支持pytest>;=4.1
V2019.1.6.后1
- 除了锁定到pytest<;4.0之外,没有做任何更改
V2019.1.6
- 除了锁定到pytest<;4.1之外,没有做任何更改
2017.11.11版
- 允许将字符串传递给register函数,该函数将成为助手名称
2016.7.10版
- 允许已注册的函数继续作为常规函数运行。#4。
2016.4.5版
- 使用包装类而不是向函数添加属性。
2016.4.3版
- 当helper函数或命名空间被
已重写。#1
2016.3.2版
- 首次工作释放
这个Pytest插件是用Cookiecutter和 @hackebrot的Cookiecutter-pytest-plugin模板。