python - Pytest fixture 返回倍数

标签 python pytest

是否有可能有一个返回字典和数据帧的装置?

import somefile
import pytest

@pytest.fixture()
def setup():
    dictionary, dataframe = somefile.get_Di_And_Df()
    return(dictionary, dataframe)

def test_check(setup):
    assert dictionary['movie']['action'] == 'Avengers'
    assert dataframe.shape[0] == 5

最佳答案

fixture 的返回值(或产生值)实际上是在测试执行期间作为函数参数注入(inject)的对象:

def test_check(setup):
    dictionary, dataframe = setup
    assert dictionary['movie']['action'] == 'Avengers'
    assert dataframe.shape[0] == 5

关于python - Pytest fixture 返回倍数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52305185/

相关文章:

python - 模块化固定装置时,PyTest 在具有多个测试文件的目录上失败

python - 如何在 py.test 运行中多次重复每个测试?

python - pytest-mock 补丁上下文管理器在退出时不恢复对象

python - BS4,在未闭合的 <br> 之间进行精确匹配

python - 使用 python 解析 HTML 页面

python - 如何自定义 Pandas 日期时间戳 @ x 轴

python - 如何使 pytest 驱动程序实例在我的测试用例中可用?

python - 用于具有多个左连接的 SQL 查询的 Django ORM

python - pyspark - LinearRegression.load() 抛出 NoSuchMethodException

python - 使用 mock.patch 给我 AttributeError ("<module ' 包 1'' > 没有属性 'myfunc' “?