Closed lovetheguitar closed 6 days ago
Here's how I would go about this:
testing/python/raises.py
is where the existing tests are for pytest.raises
pytester
would be a good fit here.test_raises_as_contextmanager
as inspiration, but instead of matching that the test case passed, you use result.stdout.fnmatch_lines
to see what output pytest produces when the pattern is invalid.(line numbers slightly different, not sure what version @lovetheguitar was on above)
code.py
) is the more internal machinery in pytest. It might be used across different places, some of which are not user-facing. So this would be the wrong place to do this kind of change.RaisesContext
) seems like the better place.pytest.fail(...)
, which is how we explicitely fail a test case nicely.re.error
) and turn it into a pytest.fail
call with a nice message
Using an invalid regex in
pytest.raises
fails in a messy way.Proposal would be to handle regex failures within
pytest.raises
and fail nicely for the user (UsageError
).pip list
from the virtual environment you are using