Code : Test1.py
import pytest
@pytest.fixture(scope='session', autouse=True)
def tc_setup(start):
if start == "20d":
print('20d is sent')
else:
print('not in list')
def pytest_addoption(parser):
parser.addoption('--start')
@pytest.fixture(scope='session', autouse=True)
def start(request):
return request.config.getoption('--start')
From Command Line
pytest -v test1.py --start=20d
Also tried,
pytest -v test1.py --start 20d
Error Message
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --start=20d
inifile: None
How can I send parameters from command line and pytest
.
I'm running this from bash shell on linux ubuntu terminal.
Version
pytest 7.1.0
Here's how it worked for me. Created two files :
conftest.py
andmyso_test.py
. You basically need to have a conftest fileconftest.py
myso_test.py
Running the command:
Output:
Running the command:
Output: