I need to ensure an error is raised using pytest given the following:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-x', required=True)
parser.parse_args()
which without passing something to -x flag when called, will result in:
usage: my_script.py [-h] -x X
my_script.py: error: the following arguments are required: -x
Which if I intentionally tried to create an ambiguous type error, probably I won't be able to come up with a better one. I need to specify some error type to be checked like the following:
with pytest.raises(SomeError):
test_condition()
Even wrapping things in try and except blocks won't work, and so far I tried KeyError, ValueError, SystemError, SystemExit, argparse.ArgumentError, KeyError, Exception ... and nothing seems to work.