简体   繁体   中英

How to use command line arguments in pytest without modifying conftest.py

I need to pass the path to 2 files using command line arguments in a pytest.

I have looked into many answers but they all require modifying conftest.py How to pass arguments in pytest by command line

Is there anyway to add arguments that can be used in a test script without modifying conftest.py?

Ideally, I would like to do this within the test file but it's not necessarily required. I have tried to import argparse in the test file to add the additional arguments but it didn't work

pytest hooks, including pytest_addoption must be defined in either a plugin or a conftest.py file

see also:


disclaimer: I'm a pytest core dev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM