Skip to content

Commit

Permalink
fixes grappa-py#52 hide common traceback for pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
sgissinger committed Nov 23, 2020
1 parent 0976548 commit f328b8b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions grappa/assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def __call__(self, expected, *args, **kw):
raise RuntimeError('grappa: operator already called')
if not self._called:
self._called = True

__tracebackhide__ = True
return self._fn(expected, *args, **kw)

def _match_alias(self, name):
Expand Down
1 change: 1 addition & 0 deletions grappa/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def assertion(subject):

# Trigger tests on function call if running as chained call
if self.ctx.chained or self.ctx.subject is not empty:
__tracebackhide__ = True
return self.test._trigger()

return self.test
Expand Down
9 changes: 9 additions & 0 deletions grappa/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def __call__(self, subject, overload=False):
grappa.Test: new test instance with the given subject.
"""
self._ctx.subject = subject

__tracebackhide__ = True
return self._trigger() if overload else Test(subject)

def __getattr__(self, name):
Expand Down Expand Up @@ -110,6 +112,7 @@ def _trigger(self):

# If error is present, raise it!
if err:
__tracebackhide__ = True
raise err

return self
Expand Down Expand Up @@ -190,27 +193,33 @@ def __overload__(self, subject):
fork._ctx.chained = True
fork._ctx.subject = self._ctx.subject
# Trigger assertions

__tracebackhide__ = True
return fork._trigger()

# Otherwise invoke the test function with a subject
__tracebackhide__ = True
return self.__call__(subject, overload=True)

def __or__(self, value):
"""
Overloads ``|`` as from left-to-right operator precedence expression.
"""
__tracebackhide__ = True
return self.__overload__(value)

def __ror__(self, value):
"""
Overloads ``|`` operator.
"""
__tracebackhide__ = True
return self.__overload__(value)

def __gt__(self, value):
"""
Overloads ``>`` operator.
"""
__tracebackhide__ = True
return self.__overload__(value)

def __enter__(self):
Expand Down

0 comments on commit f328b8b

Please sign in to comment.