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): def wait_for(self, timeout=None, **kwargs):
"""Extend wait_for to add divisor if a test is xfailing.""" """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') xfail = self.request.node.get_marker('xfail')
if xfail and xfail.args[0]: if xfail and xfail.args[0]:
kwargs['divisor'] = 10 kwargs['divisor'] = 10
@ -347,7 +349,7 @@ class QuteProc(testprocess.Process):
def after_test(self): def after_test(self):
"""Handle unexpected/skip logging and clean up after each test.""" """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 bad_msgs = [msg for msg in self._data
if self._is_error_logline(msg) and not msg.expected] 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, def wait_for_load_finished_url(self, url, *, timeout=None,
load_status='success'): load_status='success'):
"""Wait until a URL has finished loading.""" """Wait until a URL has finished loading."""
__tracebackhide__ = True __tracebackhide__ = (lambda e: e.errisinstance(
testprocess.WaitForTimeout))
if timeout is None: if timeout is None:
if 'CI' in os.environ: if 'CI' in os.environ:
@ -496,7 +499,8 @@ class QuteProc(testprocess.Process):
def wait_for_load_finished(self, path, *, port=None, https=False, def wait_for_load_finished(self, path, *, port=None, https=False,
timeout=None, load_status='success'): timeout=None, load_status='success'):
"""Wait until a path has finished loading.""" """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) url = self.path_to_url(path, port=port, https=https)
self.wait_for_load_finished_url(url, timeout=timeout, self.wait_for_load_finished_url(url, timeout=timeout,
load_status=load_status) load_status=load_status)
@ -562,7 +566,7 @@ class QuteProc(testprocess.Process):
partial_compare is used, which means only the keys/values listed will partial_compare is used, which means only the keys/values listed will
be compared. be compared.
""" """
__tracebackhide__ = True __tracebackhide__ = lambda e: e.errisinstance(pytest.fail.Exception)
# Translate ... to ellipsis in YAML. # Translate ... to ellipsis in YAML.
loader = yaml.SafeLoader(expected) loader = yaml.SafeLoader(expected)
loader.add_constructor('!ellipsis', lambda loader, node: ...) 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 Also checks self._invalid so the test counts as failed if there were
unexpected output lines earlier. unexpected output lines earlier.
""" """
__tracebackhide__ = True __tracebackhide__ = lambda e: e.errisinstance(ProcessExited)
self.captured_log = [] self.captured_log = []
if self._invalid: if self._invalid:
# Wait for a bit so the full error has a chance to arrive # 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. Return: either the found line or None.
""" """
__tracebackhide__ = True
for line in self._data: for line in self._data:
matches = [] matches = []
@ -362,7 +361,7 @@ class Process(QObject):
Called via wait_for. Called via wait_for.
""" """
__tracebackhide__ = True __tracebackhide__ = lambda e: e.errisinstance(WaitForTimeout)
message = kwargs.get('message', None) message = kwargs.get('message', None)
if message is not None: if message is not None:
elided = quteutils.elide(repr(message), 50) elided = quteutils.elide(repr(message), 50)
@ -441,7 +440,7 @@ class Process(QObject):
Return: Return:
The matched line. The matched line.
""" """
__tracebackhide__ = True __tracebackhide__ = lambda e: e.errisinstance(WaitForTimeout)
if timeout is None: if timeout is None:
if do_skip: 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 If nothing is found in the log, we wait for delay ms to make sure
nothing arrives. nothing arrives.
""" """
__tracebackhide__ = True __tracebackhide__ = lambda e: e.errisinstance(BlacklistedMessageError)
try: try:
line = self.wait_for(timeout=delay, override_waited_for=True, line = self.wait_for(timeout=delay, override_waited_for=True,
**kwargs) **kwargs)