Only display exception type if no traceback

Update test to match
This commit is contained in:
George Edward Bulmer 2018-02-12 13:43:22 +00:00
parent 164b2a3eef
commit ce8b457bac
2 changed files with 6 additions and 4 deletions

View File

@ -92,9 +92,11 @@ class ConfigErrorDesc:
traceback = attr.ib(None)
def __str__(self):
return '{} - {}: {} '.format(self.text,
self.exception.__class__.__name__,
self.exception)
if self.traceback:
return '{} - {}: {} '.format(self.text,
self.exception.__class__.__name__,
self.exception)
return '{}: {}'.format(self.text, self.exception)
def with_text(self, text):
"""Get a new ConfigErrorDesc with the given text appended."""

View File

@ -74,7 +74,7 @@ def test_config_file_errors_str(errors):
assert str(errors).splitlines() == [
'Errors occurred while reading config.py:',
' Error text 1: Exception 1',
' Error text 2: Exception 2',
' Error text 2 - Exception: Exception 2 ',
]