Reputation: 3156
I'm doing some verification in pytest's pytest_sessionstart
in conftest.py
and if the verification fails I raise ValueError
.
This works, but the printed error is pretty brutal with lots of INTERNALERROR
lines that makes it confusing to read.
I was looking to something more clean with just my error message. Is there a way to do that?
Upvotes: 2
Views: 692
Reputation: 66251
Use pytest.exit
:
import pytest
def precondition():
raise ValueError('precondition failed')
def pytest_sessionstart(session):
try:
precondition()
except ValueError as err:
pytest.exit(str(err), returncode=1)
Example output:
$ pytest
Exit: precondition failed
!!!!!!!!!!!!!!!!!!!!!!!! _pytest.outcomes.Exit: precondition failed !!!!!!!!!!!!!!!!!!!!!!!!!
Upvotes: 3