我想将输入作为命令行选项传递给pytest文件. https://stackoverflow.com/a/42145604/8031479这个问题很有帮助,但我不知道添加多个解析器采用.
我尝试将其添加到我的conftest.py文件中,但没有帮助:
def pytest_addoption(parser):
"""
This function is used to extract input1 and input2 values from the command line
"""
parser.addoption(
"--input1",action="store",default="input1"
)
parser.addoption(
"--input2",default="input2"
)
我的test.py文件的内容:
import pytest
@pytest.fixture()
def get_input1(input1):
print 'input1:',input1
return input1
# @pytest.mark.unit
@pytest.fixture()
def get_input2(input2):
print 'input2:',input2
return input2
def test_hello(get_input1,get_input2):
print 'testing pytest fixtures with command line options'
print get_input1,get_input2
这是我运行test.py文件的命令:
py.test test.py --input1="hello" --input2="world"
我收到此错误消息:
@pytest.fixture()
def get_input1(input1):
E fixture 'input1' not found
> available fixtures: cache,capfd,capfdbinary,caplog,capsys,capsysbinary,doctest_namespace,get_input1,get_input2,metadata,monkeypatch,pytestconfig,record_property,record_xml_attribute,recwarn,tmp_path,tmp_path_factory,tmpdir,tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.