Skip to content

Commit

Permalink
a more succinct notion of failure reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfalcao committed Sep 23, 2023
1 parent bf7ec59 commit 09ea6d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
5 changes: 2 additions & 3 deletions sure/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ def __init__(self, scenario_result):
class ImmediateError(RuntimeInterruption):
def __init__(self, scenario_result):
self.args = scenario_result.error.args
self.message = " ".join(self.args)
super().__init__(scenario_result)
self.message = "".join(self.args)


class ImmediateFailure(RuntimeInterruption):
def __init__(self, scenario_result):
self.args = scenario_result.failure.args
self.message = " ".join(self.args)
super().__init__(scenario_result)
self.message = self.result.succinct_failure


class ExitError(SystemExit):
Expand Down
4 changes: 1 addition & 3 deletions sure/reporters/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ def on_scenario_done(self, test, result):
def on_failure(self, test, error):
self.failures.append(test)
self.indentation += 2
sh.yellow(ballot)
sh.reset("\n")
sh.reset(" " * self.indentation)
import ipdb;ipdb.set_trace()
sh.yellow(" ".join(error.args))
sh.yellow(error.result.succinct_failure)
sh.reset("\n")
self.indentation -= 2

Expand Down
28 changes: 20 additions & 8 deletions sure/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ def run(self, reporter, runtime: RuntimeOptions):

self.run_complements(context)
results.append(result)

if result.is_failure:
reporter.on_failure(scenario, result.failure)
reporter.on_failure(scenario, result.succinct_failure)
if runtime.immediate:
raise ExitFailure(context, result)

Expand Down Expand Up @@ -175,11 +174,18 @@ def __init__(self, test, ancestor=None):
self.line = self.code.co_firstlineno
self.kind = self.test.__class__
self.name = self.test.__func__.__name__
self.ancestor = ancestor
self.ancestral_description = ""
self.ancestor_repr = ""
if ancestor:
self.ancestral_description = ancestor.description or ancestor.__doc__ or ""
self.ancestral_description = getattr(ancestor, 'description', "") or getattr(ancestor, '__doc__', "")
self.ancestor_repr = f'({self.ancestor.__module__}.{self.ancestor.__name__})'

self.description = self.test.__func__.__doc__ or ""

def __repr__(self):
return ' '.join([self.name, 'at', self.ort])

def __str__(self):
return "\n".join([
f'the scenario "{self.description}" ',
Expand Down Expand Up @@ -249,7 +255,7 @@ def run_single_test(self, test, context):
code = test.__code__
varnames = set(code.co_varnames).intersection({"context"})
argcount = len(varnames)
location = TestLocation(test)
location = TestLocation(test, isinstance(self.object, type) and self.object or None)
self.log.set_location(location)
try:
if argcount == 0:
Expand Down Expand Up @@ -340,7 +346,7 @@ def is_failure(self):
@property
def failure(self) -> Optional[AssertionError]:
if self.is_failure:
return self.sucinct_assertion()
return self.__failure__

@property
def is_success(self) -> bool:
Expand All @@ -350,9 +356,15 @@ def is_success(self) -> bool:
def ok(self):
return self.is_success

def sucinct_assertion(self) -> str:
# XXX: strip callable identifier
import ipdb;ipdb.set_trace()
@property
def succinct_failure(self) -> str:
if not self.is_failure:
return ""

assertion = self.__failure__.args[0]
assertion = assertion.replace(self.location.name, '')
assertion = assertion.replace(self.location.ancestor_repr, '')
return assertion.strip()


class ScenarioResultSet(ScenarioResult):
Expand Down

0 comments on commit 09ea6d1

Please sign in to comment.