[英]Can I define functions other than fixtures in conftest.py
我可以在 conftest.py 中定义固定装置以外的功能吗
如果我有一个 function add(),在 conftest.py 中定义
我可以在 test_add.py 文件中使用 function 只需调用 add()
两种可能的方式
您可以从 conftest.py 中导入 function 添加,或将其移至更合适的位置。 (例如 utils.py)
您可以创建返回 function 的夹具并在您的测试中使用它。 像这样的东西。
conftest.py
import pytest
@pytest.fixture
def add():
def inner_add(x, y):
return x + y
return inner_add
test_all.py
def test_all(add):
assert add(1, 2) == 3
我无法想象什么时候它会是一个很好的解决方案。 但我确信它存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.