diff options
author | Anthony Sottile <asottile@umich.edu> | 2018-10-28 16:44:34 -0700 |
---|---|---|
committer | Anthony Sottile <asottile@umich.edu> | 2018-10-29 08:38:10 -0700 |
commit | 0d1f142b1cbc5b8379217895df098f2f21ea8fad (patch) | |
tree | 303357f9617b0fec4fe57989667c4cd1eb5265ed | |
parent | 8c475a45bbf345022237755a62517384741e289f (diff) | |
download | pytest-0d1f142b1cbc5b8379217895df098f2f21ea8fad.tar.gz |
Swallow warnings during anonymous compilation of source
-rw-r--r-- | changelog/4260.bugfix.rst | 1 | ||||
-rw-r--r-- | src/_pytest/_code/source.py | 7 |
2 files changed, 7 insertions, 1 deletions
diff --git a/changelog/4260.bugfix.rst b/changelog/4260.bugfix.rst new file mode 100644 index 000000000..e1e1a009f --- /dev/null +++ b/changelog/4260.bugfix.rst @@ -0,0 +1 @@ +Swallow warnings during anonymous compilation of source. diff --git a/src/_pytest/_code/source.py b/src/_pytest/_code/source.py index fa0ecaa69..b74ecf88e 100644 --- a/src/_pytest/_code/source.py +++ b/src/_pytest/_code/source.py @@ -8,6 +8,7 @@ import linecache import sys import textwrap import tokenize +import warnings from ast import PyCF_ONLY_AST as _AST_FLAG from bisect import bisect_right @@ -288,7 +289,11 @@ def get_statement_startend2(lineno, node): def getstatementrange_ast(lineno, source, assertion=False, astnode=None): if astnode is None: content = str(source) - astnode = compile(content, "source", "exec", _AST_FLAG) + # See #4260: + # don't produce duplicate warnings when compiling source to find ast + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + astnode = compile(content, "source", "exec", _AST_FLAG) start, end = get_statement_startend2(lineno, astnode) # we need to correct the end: |