Skip to content

internal error on pytest.raises() as foobar (pytest 3.7 regression #4386

@henzef

Description

@henzef

I found a regression from pytest 3.6.4 to 3.7.0 (or 3.7.4 or 3.10.1).

pytest crashes with the following backtrace:

$ pytest -vv -l
============================= test session starts ==============================
platform cygwin -- Python 3.6.4, pytest-3.10.1, py-1.5.4, pluggy-0.7.1 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/user/temp, inifile:
collecting ... collected 1 item

test_dummy.py::test_myfun
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/main.py", line 184, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/main.py", line 224, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/main.py", line 245, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/runner.py", line 77, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/runner.py", line 92, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/runner.py", line 174, in call_and_report
INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/hooks.py", line 258, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/callers.py", line 196, in _multicall
INTERNALERROR>     gen.send(outcome)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/skipping.py", line 127, in pytest_runtest_makereport
INTERNALERROR>     rep = outcome.get_result()
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/runner.py", line 251, in pytest_runtest_makereport
INTERNALERROR>     longrepr = item.repr_failure(excinfo)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/python.py", line 739, in repr_failure
INTERNALERROR>     return self._repr_failure_py(excinfo, style=style)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/nodes.py", line 393, in _repr_failure_py
INTERNALERROR>     truncate_locals=truncate_locals,
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/_code/code.py", line 513, in getrepr
INTERNALERROR>     return fmt.repr_excinfo(self)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/_code/code.py", line 761, in repr_excinfo
INTERNALERROR>     reprtraceback = self.repr_traceback(excinfo)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/_code/code.py", line 706, in repr_traceback
INTERNALERROR>     reprentry = self.repr_traceback_entry(entry, einfo)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/_code/code.py", line 676, in repr_traceback_entry
INTERNALERROR>     localsrepr = self.repr_locals(entry.locals)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/_code/code.py", line 638, in repr_locals
INTERNALERROR>     str_repr = pprint.pformat(value)
INTERNALERROR>   File "/usr/lib/python3.6/pprint.py", line 58, in pformat
INTERNALERROR>     compact=compact).pformat(object)
INTERNALERROR>   File "/usr/lib/python3.6/pprint.py", line 144, in pformat
INTERNALERROR>     self._format(object, sio, 0, 0, {}, 0)
INTERNALERROR>   File "/usr/lib/python3.6/pprint.py", line 161, in _format
INTERNALERROR>     rep = self._repr(object, context, level)
INTERNALERROR>   File "/usr/lib/python3.6/pprint.py", line 393, in _repr
INTERNALERROR>     self._depth, level)
INTERNALERROR>   File "/usr/lib/python3.6/pprint.py", line 405, in format
INTERNALERROR>     return _safe_repr(object, context, maxlevels, level)
INTERNALERROR>   File "/usr/lib/python3.6/pprint.py", line 555, in _safe_repr
INTERNALERROR>     rep = repr(object)
INTERNALERROR>   File "/usr/lib/python3.6/site-packages/_pytest/_code/code.py", line 428, in __repr__
INTERNALERROR>     return "<ExceptionInfo %s tblen=%d>" % (self.typename, len(self.traceback))
INTERNALERROR> AttributeError: 'ExceptionInfo' object has no attribute 'typename'

========================= no tests ran in 0.23 seconds =========================

Minimal example:

import pytest

def test_myfun():
    with pytest.raises(AssertionError) as exc_info:  # ommiting the " as exc_info" here "fixes" the bug
        pass

Also note that the commandline is important to reproduce the issue: pytest -vv -l as ommiting one of the arguments (or using -v instead of -vv) prevents the bug from occuring.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: reportingrelated to terminal output and user-facing messages and errorstype: bugproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previously

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions