Use a nice string repr for ConftestImportFailure

The default message is often hard to read:

    E   _pytest.config.ConftestImportFailure: (local('D:\\projects\\pytest\\.tmp\\root\\foo\\conftest.py'), (<class 'RuntimeError'>, RuntimeError('some error',), <traceback object at 0x000001CCC3E39348>))

Using a shorter message is better:

    E   _pytest.config.ConftestImportFailure: RuntimeError: some error (from D:\projects\pytest\.tmp\root\foo\conftest.py)

And we don't really lose any information due to exception chaining.
This commit is contained in:
Bruno Oliveira
2020-05-16 16:05:12 -03:00
parent 5eaebc1900
commit 9e1e7fcabe
2 changed files with 23 additions and 1 deletions

View File

@@ -88,10 +88,15 @@ class ExitCode(enum.IntEnum):
class ConftestImportFailure(Exception):
def __init__(self, path, excinfo):
Exception.__init__(self, path, excinfo)
super().__init__(path, excinfo)
self.path = path
self.excinfo = excinfo # type: Tuple[Type[Exception], Exception, TracebackType]
def __str__(self):
return "{}: {} (from {})".format(
self.excinfo[0].__name__, self.excinfo[1], self.path
)
def main(args=None, plugins=None) -> Union[int, ExitCode]:
""" return exit code, after performing an in-process test run.