Я хочу передать входные данные в мой файл 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", action="store", 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.