(self)
| 2312 | class WarningsTest(BaseTest): |
| 2313 | |
| 2314 | def test_warnings(self): |
| 2315 | with warnings.catch_warnings(): |
| 2316 | logging.captureWarnings(True) |
| 2317 | self.addCleanup(logging.captureWarnings, False) |
| 2318 | warnings.filterwarnings("always", category=UserWarning) |
| 2319 | stream = io.StringIO() |
| 2320 | h = logging.StreamHandler(stream) |
| 2321 | logger = logging.getLogger("py.warnings") |
| 2322 | logger.addHandler(h) |
| 2323 | warnings.warn("I'm warning you...") |
| 2324 | logger.removeHandler(h) |
| 2325 | s = stream.getvalue() |
| 2326 | h.close() |
| 2327 | self.assertGreater(s.find("UserWarning: I'm warning you...\n"), 0) |
| 2328 | |
| 2329 | # See if an explicit file uses the original implementation |
| 2330 | a_file = io.StringIO() |
| 2331 | warnings.showwarning("Explicit", UserWarning, "dummy.py", 42, |
| 2332 | a_file, "Dummy line") |
| 2333 | s = a_file.getvalue() |
| 2334 | a_file.close() |
| 2335 | self.assertEqual(s, |
| 2336 | "dummy.py:42: UserWarning: Explicit\n Dummy line\n") |
| 2337 | |
| 2338 | def test_warnings_no_handlers(self): |
| 2339 | with warnings.catch_warnings(): |
nothing calls this directly
no test coverage detected