Skip to content

Commit 04845c8

Browse files
committed
Explain coverage pragmas
1 parent 0855d7c commit 04845c8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/trio/_core/_tests/test_thread_cache.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,22 @@ def foo() -> None:
221221
# if this test fails, this will hang, triggering a timeout.
222222
os.waitpid(child_pid, 0)
223223
else:
224+
# this is necessary because os._exit doesn't unwind the stack,
225+
# so coverage doesn't get to automatically stop and save
226+
# coverage information.
224227
try:
225228
import coverage
226229

227230
cov = coverage.Coverage.current()
231+
# the following pragmas are necessary because if coverage:
232+
# - isn't running, then it can't record the branch not
233+
# taken
234+
# - isn't installed, then it can't record the ImportError
235+
228236
if cov: # pragma: no branch
229237
cov.stop()
230238
cov.save()
231239
except ImportError: # pragma: no cover
232240
pass
233241

234-
os._exit(0) # pragma: no cover
242+
os._exit(0) # pragma: no cover # coverage was stopped above.

0 commit comments

Comments
 (0)