首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调用其他fixture中的fixture,并在测试中使用第二个fixture

调用其他fixture中的fixture,并在测试中使用第二个fixture
EN

Stack Overflow用户
提问于 2021-10-14 10:19:46
回答 1查看 48关注 0票数 0

我有这样的情况:

conftest.py

代码语言:javascript
复制
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 element

test_file.py

代码语言:javascript
复制
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中可行吗?

EN

回答 1

Stack Overflow用户

发布于 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。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69568977

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档