How can I define custom command line arguments, and make them mandatory in pytest?
For example, I want something like this:
pytest -s sample.py --test_suite='some_value'
And the command line argument --test_suite has to be mandatory. If it's missing, I want to throw a "help" message like, "enter the test_suite to be executed".
This is my code:
@pytest.fixture
def testsuite(request):
    test_suite = request.config.getoption('--test_suite')
    return test_suite
def pytest_addoption(parser):
    parser.addoption("--test_suite",action="store",default="default_suite",
                     help="Enter the test suite you want to execute."
                          "Ex. --test_suite=default_suite"
                          "If nothing is selected, default_suite tests will be run.")   
This approach makes the command line arguments optional. But I want to make them mandatory.
To mark a command line argument as mandatory using addoption, add required=True as a keyword argument to the method call
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With