New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest rethrows Exception poorly. losing traceback information. #1516

Closed
SuperDoxin opened this Issue Apr 15, 2016 · 4 comments

Comments

Projects
None yet
4 participants
@SuperDoxin

SuperDoxin commented Apr 15, 2016

In config.py pytest catches all Exceptions and rethrows them (poorly) as conftestImportFailure, losing the original traceback. this makes bug hunting rather tricky since the traceback pytest gives doesn't point at all to the cause of the error.

either throwing the original exception or rethrowing properly would be a good solution.

@The-Compiler

This comment has been minimized.

Member

The-Compiler commented Apr 15, 2016

Could you show an example where the original traceback isn't shown? I just tried with raise Exception in a conftest.py and I see the traceback of that:

Traceback (most recent call last):
  File "/home/florian/proj/qutebrowser/git/.tox/py34/lib/python3.4/site-packages/_pytest/config.py", line
    return self._path2confmods[path]
KeyError: local('/home/florian/proj/qutebrowser/git/tests')

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/florian/proj/qutebrowser/git/.tox/py34/lib/python3.4/site-packages/_pytest/config.py", line
    return self._conftestpath2mod[conftestpath]
KeyError: local('/home/florian/proj/qutebrowser/git/tests/conftest.py')

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/florian/proj/qutebrowser/git/.tox/py34/lib/python3.4/site-packages/_pytest/config.py", line
    mod = conftestpath.pyimport()
  File "/home/florian/proj/qutebrowser/git/.tox/py34/lib/python3.4/site-packages/py/_path/local.py", line
    __import__(modname)
  File "/home/florian/proj/qutebrowser/git/tests/conftest.py", line 167, in <module>
    raise Exception
Exception
ERROR: could not load /home/florian/proj/qutebrowser/git/tests/conftest.py
@astraw38

This comment has been minimized.

astraw38 commented Apr 15, 2016

@The-Compiler This is what I see, I'm working on getting a simple reproduction.

  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 249, in _wrapped_call
    wrap_controller.send(call_outcome)
  File "/usr/local/lib/python2.7/site-packages/_pytest/helpconfig.py", line 28, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
    _reraise(*ex)  # noqa
  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
    self.result = func()
  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
    res = hook_impl.function(*args)
  File "/usr/local/lib/python2.7/site-packages/_pytest/config.py", line 856, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/local/lib/python2.7/site-packages/_pytest/config.py", line 961, in parse
    self._preparse(args, addopts=addopts)
  File "/usr/local/lib/python2.7/site-packages/_pytest/config.py", line 932, in _preparse
    args=args, parser=self._parser)
  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 253, in _wrapped_call
    return call_outcome.get_result()
  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
    _reraise(*ex)  # noqa
  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
    self.result = func()
  File "/usr/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
    res = hook_impl.function(*args)
  File "/usr/local/lib/python2.7/site-packages/_pytest/config.py", line 902, in pytest_load_initial_conftests
    self.pluginmanager._set_initial_conftests(early_config.known_args_namespace)
  File "/usr/local/lib/python2.7/site-packages/_pytest/config.py", line 266, in _set_initial_conftests
    self._try_load_conftest(anchor)
  File "/usr/local/lib/python2.7/site-packages/_pytest/config.py", line 272, in _try_load_conftest
    self._getconftestmodules(anchor)
  File "/usr/local/lib/python2.7/site-packages/_pytest/config.py", line 297, in _getconftestmodules
    mod = self._importconftest(conftestpath)
  File "/usr/local/lib/python2.7/site-packages/_pytest/config.py", line 322, in _importconftest
    raise ConftestImportFailure(conftestpath, sys.exc_info())
_pytest.config.ConftestImportFailure: (local('/home/<snip>conftest.py'), (<type 'exceptions.Exception'>, Exception(), <traceback object at 0xb3185234>))
@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Apr 15, 2016

Yep, that seems to be the case with Python 2...

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Jul 21, 2016

Merged in #1702

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment