通过在 @pytest.mark.parametrize 中传递 conftest.py 中定义的装置,我收到以下错误:
pytest --alist="0220,0221" test_1.py -v -s
NameError: name 'alist' is not defined
conftest.py:
def pytest_addoption(parser):
parser.addoption("--alist", action="store")
@pytest.fixture
def alist(request):
return request.config.getoption("--alist").split(",")
测试_1.py:
@pytest.mark.parametrize("channel", alist, scope="class")
class TestRaIntegrationReplay:
def test_ra_start_time(self, channel):
print(channel)
如果我将 alist 作为固定装置传递给测试,例如:
def test_ra_start_time(self, alist):
for channel in alist:
print(channel)
它工作得很好,但它不适用于传递给 @pytest.mark.parametrize