TypeError: parametrize() 得到参数“间接”的多个值

问题描述 投票:0回答:0

我正在尝试通过从外部函数获取值来参数化我的 pytest,我的方法是这样的:

import pytest
from Utilities.MiscUtils import generate_random_email_for_registration
from Utilities.TextFileUtils import read_text_file


generate_random_email_for_registration()

这里 generate_random_email_for_registration() 将生成随机电子邮件地址并将其存储到文本文件中。

我的 pytest 标记是这样的:

@pytest.mark.parametrize("email", "password", [(read_text_file("email"), "Test@12345")], indirect=["email"])

(read_text_file("email") 作为这种方法,将从 email.txt 文件中获取我的价值。

现在当我执行时,出现以下错误:

/Users/tp/AndroidPythonAppium/lib/python3.9/site-packages/pluggy/_hooks.py:265: in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
/Users/tp/AndroidPythonAppium/lib/python3.9/site-packages/pluggy/_manager.py:80: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
/Users/tp/AndroidPythonAppium/lib/python3.9/site-packages/_pytest/python.py:272: in pytest_pycollect_makeitem
    return list(collector._genfunctions(name, obj))
/Users/tp/AndroidPythonAppium/lib/python3.9/site-packages/_pytest/python.py:499: in _genfunctions
    self.ihook.pytest_generate_tests.call_extra(methods, dict(metafunc=metafunc))
/Users/tp/AndroidPythonAppium/lib/python3.9/site-packages/pluggy/_hooks.py:292: in call_extra
    return self(**kwargs)
/Users/tp/AndroidPythonAppium/lib/python3.9/site-packages/pluggy/_hooks.py:265: in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
/Users/tp/AndroidPythonAppium/lib/python3.9/site-packages/pluggy/_manager.py:80: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
/Users/tp/AndroidPythonAppium/lib/python3.9/site-packages/_pytest/python.py:151: in pytest_generate_tests
    metafunc.parametrize(*marker.args, **marker.kwargs, _param_mark=marker)
E   TypeError: parametrize() got multiple values for argument 'indirect'

我需要知道我在哪里犯了错误,因为这也可以通过不使用 pytest.parametrize 来完成,但我在这里使用的是好的做法。

python-3.x pytest pytest-fixtures
© www.soinside.com 2019 - 2024. All rights reserved.