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

Method test_check_warnings

Lib/test/test_warnings/__init__.py:1454–1483  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1452 self.assertEqual(log, [])
1453
1454 def test_check_warnings(self):
1455 # Explicit tests for the test.support convenience wrapper
1456 wmod = self.module
1457 if wmod is not sys.modules['warnings']:
1458 self.skipTest('module to test is not loaded warnings module')
1459 with warnings_helper.check_warnings(quiet=False) as w:
1460 self.assertEqual(w.warnings, [])
1461 wmod.simplefilter("always")
1462 wmod.warn("foo")
1463 self.assertEqual(str(w.message), "foo")
1464 wmod.warn("bar")
1465 self.assertEqual(str(w.message), "bar")
1466 self.assertEqual(str(w.warnings[0].message), "foo")
1467 self.assertEqual(str(w.warnings[1].message), "bar")
1468 w.reset()
1469 self.assertEqual(w.warnings, [])
1470
1471 with warnings_helper.check_warnings():
1472 # defaults to quiet=True without argument
1473 pass
1474 with warnings_helper.check_warnings(('foo', UserWarning)):
1475 wmod.warn("foo")
1476
1477 with self.assertRaises(AssertionError):
1478 with warnings_helper.check_warnings(('', RuntimeWarning)):
1479 # defaults to quiet=False with argument
1480 pass
1481 with self.assertRaises(AssertionError):
1482 with warnings_helper.check_warnings(('foo', RuntimeWarning)):
1483 wmod.warn("foo")
1484
1485class CCatchWarningTests(CatchWarningTests, unittest.TestCase):
1486 module = c_warnings

Callers

nothing calls this directly

Calls 6

strFunction · 0.85
skipTestMethod · 0.80
assertEqualMethod · 0.45
warnMethod · 0.45
resetMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected