Skip to content
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

Rendering the traceback of an HTTPError causes in INTERNALERROR #10797

Closed
icemac opened this issue Mar 6, 2023 · 2 comments · Fixed by agronholm/exceptiongroup#58
Closed

Comments

@icemac
Copy link

icemac commented Mar 6, 2023

pytest >= 7.2 uses the exceptiongroup library while rendering tracebacks.
If the exception is a urllib.error.HTTPError python/cpython#90113 occurs causing an INTERNALERROR.

(pytest < 7.2 does not have this problem.)

Minimal example:

from urllib.error import HTTPError


def test_HTTPError():
    raise HTTPError(
        'http://localhost', '500', 'Internal Server Error', hdrs=(), fp=None)

Traceback

$ bin/pytest
============================= test session starts ==============================
platform darwin -- Python 3.9.16, pytest-7.2.2, pluggy-1.0.0
rootdir: /.../pt72
collected 1 item

test_httperror.py
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/main.py", line 270, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/main.py", line 324, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/main.py", line 349, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/runner.py", line 112, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/runner.py", line 131, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/runner.py", line 222, in call_and_report
INTERNALERROR>     report: TestReport = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/pluggy/_callers.py", line 55, in _multicall
INTERNALERROR>     gen.send(outcome)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/skipping.py", line 265, in pytest_runtest_makereport
INTERNALERROR>     rep = outcome.get_result()
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/runner.py", line 366, in pytest_runtest_makereport
INTERNALERROR>     return TestReport.from_item_and_call(item, call)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/reports.py", line 349, in from_item_and_call
INTERNALERROR>     longrepr = item.repr_failure(excinfo)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/python.py", line 1823, in repr_failure
INTERNALERROR>     return self._repr_failure_py(excinfo, style=style)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/nodes.py", line 484, in _repr_failure_py
INTERNALERROR>     return excinfo.getrepr(
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/_code/code.py", line 669, in getrepr
INTERNALERROR>     return fmt.repr_excinfo(self)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/_code/code.py", line 944, in repr_excinfo
INTERNALERROR>     reprtraceback = self.repr_traceback(excinfo_)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/_code/code.py", line 871, in repr_traceback
INTERNALERROR>     reprentry = self.repr_traceback_entry(entry, einfo)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/_code/code.py", line 822, in repr_traceback_entry
INTERNALERROR>     s = self.get_source(source, line_index, excinfo, short=short)
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/_code/code.py", line 760, in get_source
INTERNALERROR>     lines.extend(self.get_exconly(excinfo, indent=indent, markall=True))
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/_code/code.py", line 772, in get_exconly
INTERNALERROR>     exlines = excinfo.exconly(tryshort=True).split("\n")
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/_pytest/_code/code.py", line 588, in exconly
INTERNALERROR>     lines = format_exception_only(self.type, self.value)
INTERNALERROR>   File "/.../lib/python3.9/traceback.py", line 140, in format_exception_only
INTERNALERROR>     return list(TracebackException(etype, value, None).format_exception_only())
INTERNALERROR>   File "/.../pt72/lib/python3.9/site-packages/exceptiongroup/_formatting.py", line 106, in __init__
INTERNALERROR>     self.__notes__ = getattr(exc_value, "__notes__", None)
INTERNALERROR>   File "/.../lib/python3.9/tempfile.py", line 472, in __getattr__
INTERNALERROR>     file = self.__dict__['file']
INTERNALERROR> KeyError: 'file'
$ bin/pip list
Package        Version
-------------- -------
attrs          22.2.0
exceptiongroup 1.1.0
iniconfig      2.0.0
packaging      23.0
pip            23.0.1
pluggy         1.0.0
pytest         7.2.2
setuptools     58.1.0
tomli          2.0.1

Using pytest 7.2.2 on Python 3.9.16

@Zac-HD
Copy link
Member

Zac-HD commented Mar 12, 2023

This isn't a Pytest bug, but I've opened agronholm/exceptiongroup#58 upstream 🙂

@Zac-HD Zac-HD closed this as completed Mar 12, 2023
@icemac
Copy link
Author

icemac commented Mar 13, 2023

@Zac-HD Thank you for fixing this issue so quickly.

michelle-aubin added a commit to reviewboard/reviewboard that referenced this issue Nov 22, 2023
`exceptiongroup` < 1.1.1 has a bug with `pytest` >= 7.2 where rendering
certain error tracebacks would cause an internal error (see
pytest-dev/pytest#10797). This sets the
`exceptiongroup` version to prevent us from encountering the bug.

Testing Done:
- Ran into this bug while running Power Pack tests, which was fixed
  after upgrading my `exceptiongroup` version to 1.1.1.
- Ran `./setup.py develop` and ran unit tests

Reviewed at https://reviews.reviewboard.org/r/13425/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants