diff options
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/env.py | 4 | ||||
-rw-r--r-- | coverage/parser.py | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/coverage/env.py b/coverage/env.py index b5da3b47..17ace169 100644 --- a/coverage/env.py +++ b/coverage/env.py @@ -17,6 +17,8 @@ PYVERSION = sys.version_info + (int(platform.python_version()[-1] == "+"),) PY2 = PYVERSION < (3, 0) PY3 = PYVERSION >= (3, 0) +NOOPT = getattr(sys.flags, "noopt", False) + # Python implementations. PYPY = (platform.python_implementation() == 'PyPy') if PYPY: @@ -80,7 +82,7 @@ class PYBEHAVIOR(object): trace_decorated_def = (PYVERSION >= (3, 8)) # Are while-true loops optimized into absolute jumps with no loop setup? - nix_while_true = (PYVERSION >= (3, 8)) + nix_while_true = (PYVERSION >= (3, 8)) and not NOOPT # Python 3.9a1 made sys.argv[0] and other reported files absolute paths. report_absolute_files = (PYVERSION >= (3, 9)) diff --git a/coverage/parser.py b/coverage/parser.py index e3e43149..9b97589b 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -1111,7 +1111,7 @@ class AstArcAnalyzer(object): def _handle__While(self, node): constant_test = self.is_constant_expr(node.test) start = to_top = self.line_for_node(node.test) - if constant_test and (env.PY3 or constant_test == "Num"): + if not env.NOOPT and constant_test and (env.PY3 or constant_test == "Num"): to_top = self.line_for_node(node.body[0]) self.block_stack.append(LoopBlock(start=to_top)) from_start = ArcStart(start, cause="the condition on line {lineno} was never true") @@ -1126,7 +1126,7 @@ class AstArcAnalyzer(object): else_exits = self.add_body_arcs(node.orelse, from_start=from_start) exits |= else_exits else: - # No `else` clause: you can exit from the start. + # No `else` clause: you can exit from the start if the condition isn't constant. if not constant_test: exits.add(from_start) return exits |