首页 > 解决方案 > Pytest:日期对象不能作为参数传递给夹具

问题描述

我尝试使用以下代码片段将日期对象作为参数传递给 pytest 夹具并在夹具中拾取它:

@pytest.fixture
def getData(request):
    """Variable data query"""
    date = request.param
    #do some data calls (with the provided date)...

@pytest.mark.parametrize("getData", [(date.today())], indirect=["getData"])
def test_data(getData):
    #do some tests with the data...

但是我收到错误消息,例如:

“请求”是否只接受字符串?是否有另一种可能将更复杂的对象(字符串除外)作为参数传递给夹具?

标签: pytest

解决方案


推荐阅读