我具有带有模块范围(create_temp_fixture)的夹具功能,该功能将产生值(名称,年龄),我想在所有测试中使用这些值。 我在Fixture函数中将“ autouse”参数值设置为“ True”,这样我就可以使用Fixture函数而无需将Fixture名称传递给测试用例作为参数。
请让我知道我在这里做错了什么。感谢您的帮助。
我尝试搜索,但没有信息。 stackoverflow中与我的问题最接近的一个问题是pytest fixture is always returning a function
@pytest.fixture(scope="module", autouse=True)
def create_temp_fixture():
name = "xyz"
age = 30
yield name, age
#Note: If i pass name of the fixture function name to test cases, its working.
def test_1():
name, age = create_temp_fixture
assert name == 'xyz'
assert age == 30
实际结果:
================================================ ====================================失败============ ================================================== ======================== ______________________________________________________________________________________ test_1 _______________________________________________________________________________________
def test_1():
name, age = create_temp_fixture
E TypeError:无法解包不可迭代的函数对象
tests / test_api.py:72:TypeError ================================================== =========================== 1在0.20秒内失败================== ================================================== ==========