summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2020-09-12 08:09:48 -0300
committerGitHub <noreply@github.com>2020-09-12 08:09:48 -0300
commit634cde9506eb1f48dec3ec77974ee8dc952207c6 (patch)
treee4059fd3b557b4005e4dc18f48cfa811b98fa485 /src
parentec58ae5bae26ec7dc0464680551769452f66bc7c (diff)
parent96a17b1683fb1bd5b49abff2e4e661084268e672 (diff)
downloadpytest-634cde9506eb1f48dec3ec77974ee8dc952207c6.tar.gz
Merge pull request #7745 from asottile/exec_globals_type_problem
Fix INTERNALERROR when accessing locals / globals with faulty `exec`
Diffstat (limited to 'src')
-rw-r--r--src/_pytest/_code/code.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py
index 12d39306a..98aea8c11 100644
--- a/src/_pytest/_code/code.py
+++ b/src/_pytest/_code/code.py
@@ -246,10 +246,20 @@ class TracebackEntry:
Mostly for internal use.
"""
- f = self.frame
- tbh = f.f_locals.get(
- "__tracebackhide__", f.f_globals.get("__tracebackhide__", False)
+ tbh = (
+ False
) # type: Union[bool, Callable[[Optional[ExceptionInfo[BaseException]]], bool]]
+ for maybe_ns_dct in (self.frame.f_locals, self.frame.f_globals):
+ # in normal cases, f_locals and f_globals are dictionaries
+ # however via `exec(...)` / `eval(...)` they can be other types
+ # (even incorrect types!).
+ # as such, we suppress all exceptions while accessing __tracebackhide__
+ try:
+ tbh = maybe_ns_dct["__tracebackhide__"]
+ except Exception:
+ pass
+ else:
+ break
if tbh and callable(tbh):
return tbh(None if self._excinfo is None else self._excinfo())
return tbh