tests: Set __tracebackhide__ to a callable

This allows us to only filter the exceptions we actually want to hide.

See #1877
This commit is contained in:
Florian Bruhin 2016-08-23 07:28:08 +02:00
parent 0c6574afb1
commit 23c4c89a0f
2 changed files with 12 additions and 9 deletions

View File

@ -295,6 +295,8 @@ class QuteProc(testprocess.Process):
def wait_for(self, timeout=None, **kwargs):
"""Extend wait_for to add divisor if a test is xfailing."""
__tracebackhide__ = (lambda e:
e.errisinstance(testprocess.WaitForTimeout))
xfail = self.request.node.get_marker('xfail')
if xfail and xfail.args[0]:
kwargs['divisor'] = 10
@ -347,7 +349,7 @@ class QuteProc(testprocess.Process):
def after_test(self):
"""Handle unexpected/skip logging and clean up after each test."""
__tracebackhide__ = True
__tracebackhide__ = lambda e: e.errisinstance(pytest.fail.Exception)
bad_msgs = [msg for msg in self._data
if self._is_error_logline(msg) and not msg.expected]
@ -464,7 +466,8 @@ class QuteProc(testprocess.Process):
def wait_for_load_finished_url(self, url, *, timeout=None,
load_status='success'):
"""Wait until a URL has finished loading."""
__tracebackhide__ = True
__tracebackhide__ = (lambda e: e.errisinstance(
testprocess.WaitForTimeout))
if timeout is None:
if 'CI' in os.environ:
@ -496,7 +499,8 @@ class QuteProc(testprocess.Process):
def wait_for_load_finished(self, path, *, port=None, https=False,
timeout=None, load_status='success'):
"""Wait until a path has finished loading."""
__tracebackhide__ = True
__tracebackhide__ = (lambda e: e.errisinstance(
testprocess.WaitForTimeout))
url = self.path_to_url(path, port=port, https=https)
self.wait_for_load_finished_url(url, timeout=timeout,
load_status=load_status)
@ -562,7 +566,7 @@ class QuteProc(testprocess.Process):
partial_compare is used, which means only the keys/values listed will
be compared.
"""
__tracebackhide__ = True
__tracebackhide__ = lambda e: e.errisinstance(pytest.fail.Exception)
# Translate ... to ellipsis in YAML.
loader = yaml.SafeLoader(expected)
loader.add_constructor('!ellipsis', lambda loader, node: ...)

View File

@ -279,7 +279,7 @@ class Process(QObject):
Also checks self._invalid so the test counts as failed if there were
unexpected output lines earlier.
"""
__tracebackhide__ = True
__tracebackhide__ = lambda e: e.errisinstance(ProcessExited)
self.captured_log = []
if self._invalid:
# Wait for a bit so the full error has a chance to arrive
@ -338,7 +338,6 @@ class Process(QObject):
Return: either the found line or None.
"""
__tracebackhide__ = True
for line in self._data:
matches = []
@ -362,7 +361,7 @@ class Process(QObject):
Called via wait_for.
"""
__tracebackhide__ = True
__tracebackhide__ = lambda e: e.errisinstance(WaitForTimeout)
message = kwargs.get('message', None)
if message is not None:
elided = quteutils.elide(repr(message), 50)
@ -441,7 +440,7 @@ class Process(QObject):
Return:
The matched line.
"""
__tracebackhide__ = True
__tracebackhide__ = lambda e: e.errisinstance(WaitForTimeout)
if timeout is None:
if do_skip:
@ -471,7 +470,7 @@ class Process(QObject):
If nothing is found in the log, we wait for delay ms to make sure
nothing arrives.
"""
__tracebackhide__ = True
__tracebackhide__ = lambda e: e.errisinstance(BlacklistedMessageError)
try:
line = self.wait_for(timeout=delay, override_waited_for=True,
**kwargs)