Skip to content

Commit

Permalink
Explain coverage pragmas
Browse files Browse the repository at this point in the history
  • Loading branch information
A5rocks committed Feb 5, 2025
1 parent 0855d7c commit 94d51b2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/trio/_core/_tests/test_thread_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,21 @@ def foo() -> None:
# if this test fails, this will hang, triggering a timeout.
os.waitpid(child_pid, 0)
else:
# this is necessary because os._exit doesn't unwind the stack,
# so coverage doesn't get to automatically stop and save
# coverage information.
try:
import coverage

cov = coverage.Coverage.current()
# the following pragmas are necessary due to not having
# necessary test runs (w/ coverage but not running under
# it, w/o coverage)

if cov: # pragma: no branch
cov.stop()
cov.save()
except ImportError: # pragma: no cover
pass

os._exit(0) # pragma: no cover
os._exit(0) # pragma: no cover # coverage was stopped above.

0 comments on commit 94d51b2

Please sign in to comment.