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

Method test_failing_import_sticks

Lib/test/test_import/__init__.py:533–551  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

531 pass
532
533 def test_failing_import_sticks(self):
534 source = TESTFN + ".py"
535 with open(source, "w", encoding='utf-8') as f:
536 print("a = 1/0", file=f)
537
538 # New in 2.4, we shouldn't be able to import that no matter how often
539 # we try.
540 sys.path.insert(0, os.curdir)
541 importlib.invalidate_caches()
542 if TESTFN in sys.modules:
543 del sys.modules[TESTFN]
544 try:
545 for i in [1, 2, 3]:
546 self.assertRaises(ZeroDivisionError, __import__, TESTFN)
547 self.assertNotIn(TESTFN, sys.modules,
548 "damaged module in sys.modules on %i try" % i)
549 finally:
550 del sys.path[0]
551 remove_files(TESTFN)
552
553 def test_import_name_binding(self):
554 # import x.y.z binds x in the current namespace

Callers

nothing calls this directly

Calls 6

remove_filesFunction · 0.85
assertNotInMethod · 0.80
openFunction · 0.50
insertMethod · 0.45
invalidate_cachesMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected