MCPcopy Create free account
hub / github.com/python/cpython / test_skip_file_prefixes

Method test_skip_file_prefixes

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

Source from the content-addressed store, hash-verified

629 self.assertEqual(w[0].filename, __file__)
630
631 def test_skip_file_prefixes(self):
632 with warnings_state(self.module):
633 with self.module.catch_warnings(record=True) as w:
634 self.module.simplefilter('always')
635
636 # Warning never attributed to the data/ package.
637 package_helper.inner_api(
638 "inner_api", stacklevel=2,
639 warnings_module=warning_tests.warnings)
640 self.assertEqual(w[-1].filename, __file__)
641 warning_tests.package("package api", stacklevel=2)
642 self.assertEqual(w[-1].filename, __file__)
643 self.assertEqual(w[-2].filename, w[-1].filename)
644 # Low stacklevels are overridden to 2 behavior.
645 warning_tests.package("package api 1", stacklevel=1)
646 self.assertEqual(w[-1].filename, __file__)
647 warning_tests.package("package api 0", stacklevel=0)
648 self.assertEqual(w[-1].filename, __file__)
649 warning_tests.package("package api -99", stacklevel=-99)
650 self.assertEqual(w[-1].filename, __file__)
651
652 # The stacklevel still goes up out of the package.
653 warning_tests.package("prefix02", stacklevel=3)
654 self.assertIn("unittest", w[-1].filename)
655
656 def test_skip_file_prefixes_file_path(self):
657 # see: gh-126209

Callers

nothing calls this directly

Calls 4

warnings_stateFunction · 0.85
assertInMethod · 0.80
assertEqualMethod · 0.45
packageMethod · 0.45

Tested by

no test coverage detected