首页 > 解决方案 > 如何使用 pytest 夹具传递字典

问题描述

以下代码给出错误“TypeError:'function'对象不可下标。

import pytest

@pytest.fixture
def get_data():
  data = {'name': 'Bill', 'age': 20}
  return data

def test_get_data(get_data):
  test_data = get_data
  assert test_data['name'] == 'Bill'
  assert test_data['age'] == 20

test_get_data(get_data)

标签: pythonpytest

解决方案


推荐阅读