MCPcopy Index your code
hub / github.com/python/cpython / test_warnings

Method test_warnings

Lib/test/test_logging.py:2340–2362  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2338class WarningsTest(BaseTest):
2339
2340 def test_warnings(self):
2341 with warnings.catch_warnings():
2342 logging.captureWarnings(True)
2343 self.addCleanup(logging.captureWarnings, False)
2344 warnings.filterwarnings("always", category=UserWarning)
2345 stream = io.StringIO()
2346 h = logging.StreamHandler(stream)
2347 logger = logging.getLogger("py.warnings")
2348 logger.addHandler(h)
2349 warnings.warn("I'm warning you...")
2350 logger.removeHandler(h)
2351 s = stream.getvalue()
2352 h.close()
2353 self.assertGreater(s.find("UserWarning: I'm warning you...\n"), 0)
2354
2355 # See if an explicit file uses the original implementation
2356 a_file = io.StringIO()
2357 warnings.showwarning("Explicit", UserWarning, "dummy.py", 42,
2358 a_file, "Dummy line")
2359 s = a_file.getvalue()
2360 a_file.close()
2361 self.assertEqual(s,
2362 "dummy.py:42: UserWarning: Explicit\n Dummy line\n")
2363
2364 def test_warnings_no_handlers(self):
2365 with warnings.catch_warnings():

Callers

nothing calls this directly

Calls 11

getvalueMethod · 0.95
addCleanupMethod · 0.80
getLoggerMethod · 0.80
addHandlerMethod · 0.80
removeHandlerMethod · 0.80
assertGreaterMethod · 0.80
showwarningMethod · 0.80
warnMethod · 0.45
closeMethod · 0.45
findMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected