我有这样的情况:
conftest.py
import pytest
@pytest.fixture
def get_table_x():
table_x = ['one', 'two', 'three'] #here is a function call that return the table
return table_x
@pytest.fixture
def get_table_y():
table_y = ['one', 'two', 'three'] #here is a function call that return the table
return table_y
@pytest.fixture(params=get_table_x) #here I receive: "TypeErrorL 'function' object is not iterable"
def get_element(request):
element = request.param
yield elementtest_file.py
import pytest
def test_len_lists(get_table_x, get_table_y):
assert len(get_table_x) == len(get_table_y) #this works fine
@pytest.mark.parametrize('item', get_element): #here, "get_element" is not visible
def test_items_name(item, get_table_y) # I need to run this test for each item
assert item in get_table_y值得一提的是,我需要从"get_element“fixture中的第一个列表生成元素,以便将每个元素用作其他fixture的输入。这种方法在pytest中可行吗?
发布于 2021-10-14 10:26:42
我想你看SeanH的描述是对的
https://www.seanh.cc/2017/02/12/advanced-fixtures/#a-fixture-can-use-multiple-other-fixtures
测试使用控制器fixture,控制器fixture使用user和pyramid_request fixture,因此测试间接使用user和pyramid_request fixture。
https://stackoverflow.com/questions/69568977
复制相似问题