Closed
Description
Bug report
Bug description:
Starting with CPython commit f6f4e8a, the coverage.py test suite fails when using sys.monitoring. A loop seems to execute one time too many:
__________________________________________________________ MatchCaseTest.test_match_case_with_wildcard ___________________________________________________________
self = <tests.test_arcs.MatchCaseTest object at 0x11014c3e0>
def test_match_case_with_wildcard(self) -> None:
self.check_coverage("""\
for command in ["huh", "go home", "go n"]:
match command.split():
case ["go", direction] if direction in "nesw":
match = f"go: {direction}"
case ["go", _]:
match = "no go"
case x:
match = f"default: {x}"
print(match)
""",
branchz="12 1-1 34 35 56 57",
branchz_missing="",
)
> assert self.stdout() == "default: ['huh']\nno go\ngo: n\n"
E assert "default: ['huh']\ndefault: ['huh']\nno go\ngo: n\n" == "default: ['huh']\nno go\ngo: n\n"
E
E + default: ['huh']
E default: ['huh']
E no go
E go: n
/Users/ned/coverage/trunk/tests/test_arcs.py:1444: AssertionError
The default: ['huh']
line is printed twice, but only when using sys.monitoring. Under sys.settrace, the test passes.
It will take a little work to make a small reproducer if you need it. Other tests fail as well that don't involve match/case, but all failures involve for loops.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS