The new ResourceWarning exceptions in Python 3.8 are ignored since
they're raised during garbage collection, which makes them easy to
miss even with PYTHONWARNINGS=error in our testing. Luckily, their
tracebacks are written to stderr, and we normally expect nothing
will be written to stderr on successful runs of the selftest script.
As a simple solution to avoid similar situations in the future,
cause the selftest run to fail if anything at all gets written to
the service's stderr.
with open("capture_stderr.log", "w") as serviceerr:
serviceerr.write(stderr.decode("utf-8"))
+ # Error if anything was written on stderr as this may indicate ignored
+ # exceptions (e.g. ResourceWarning during garbage collection)
+ if stderr:
+ tlog("\nERROR: something was written to stderr, see "
+ "capture_stderr.log for details.")
+ success = False
+
return success