[pytest-dev] No traceback filtering with __tracebackhide__ attribute using custom pytest plugin

Ringo De Smet ringo.de.smet at ontoforce.com
Tue Mar 13 05:46:44 EDT 2018


Hello,

Here I am again with a problem regarding my custom pytest plugin to run
mamba tests. In the mamba tests, I am using the the expects library. I
patched the library locally and added the attribute

__tracebackhide__ = True

to the methods marked here:

https://github.com/jaimegildesagredo/expects/blob/12bc9501b75b89a9d8b9916ee6da5ca318e72145/expects/expectations.py#L10-L19

When using the patched expects library in a regular unittest, the
stacktrace is filtered as documented.

tests/test_action_base.py:72: in test_getoption_ok
    expect(rs).to(equal('value2'))
E   AssertionError:
E   expected: 'value' to equal 'value2'

But when using the library in my mamba tests, I get a full stack trace.

./../../../.pyenv/versions/3.6.4/envs/metis/lib/python3.6/site-packages/_pytest/runner.py:192:
in __init__
    self.result = func()
../../../../.pyenv/versions/3.6.4/envs/metis/lib/python3.6/site-packages/_pytest/runner.py:178:
in <lambda>
    return CallInfo(lambda: ihook(item=item, **kwds), when=when)
../../../../.pyenv/versions/3.6.4/envs/metis/lib/python3.6/site-packages/pluggy/__init__.py:617:
in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
../../../../.pyenv/versions/3.6.4/envs/metis/lib/python3.6/site-packages/pluggy/__init__.py:222:
in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
../../../../.pyenv/versions/3.6.4/envs/metis/lib/python3.6/site-packages/pluggy/__init__.py:216:
in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
../../../../.pyenv/versions/3.6.4/envs/metis/lib/python3.6/site-packages/pluggy/callers.py:201:
in _multicall
    return outcome.get_result()
../../../../.pyenv/versions/3.6.4/envs/metis/lib/python3.6/site-packages/pluggy/callers.py:76:
in get_result
    raise ex[1].with_traceback(ex[2])
../../../../.pyenv/versions/3.6.4/envs/metis/lib/python3.6/site-packages/pluggy/callers.py:180:
in _multicall
    res = hook_impl.function(*args)
../../../../.pyenv/versions/3.6.4/envs/metis/lib/python3.6/site-packages/_pytest/runner.py:109:
in pytest_runtest_call
    item.runtest()
python-mamba/pytest_mamba/plugin.py:134: in runtest
    raise mamba_error.exception
../../../../.pyenv/versions/3.6.4/envs/metis/lib/python3.6/site-packages/mamba/example.py:43:
in _execute_test
    self.test(execution_context)
spec/action_base_spec.py:44: in 00000007__it is ok--
    expect(rs).to(equal('value2'))
../../../../.pyenv/versions/3.6.4/envs/metis/lib/python3.6/site-packages/expects/expectations.py:22:
in to
    self._assert(matcher)
../../../../.pyenv/versions/3.6.4/envs/metis/lib/python3.6/site-packages/expects/expectations.py:29:
in _assert
    raise AssertionError(self._failure_message(matcher, reasons))
E   AssertionError:
E   expected: 'value' to equal 'value2'

Am I right in saying that the pytest_runtest_makereport hook from runner.py
is the one calling into the filtering of the traceback and using the
__tracebackhide__ attribute? Why isn't this done for my custom test suite?

Ringo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20180313/db0ac583/attachment.html>


More information about the pytest-dev mailing list