Back to index

python3.2  3.2.2
Public Member Functions
test.test_import.OverridingImportBuiltinTests Class Reference

List of all members.

Public Member Functions

def test_override_builtin

Detailed Description

Definition at line 488 of file

Member Function Documentation

Definition at line 489 of file

00490     def test_override_builtin(self):
00491         # Test that overriding builtins.__import__ can bypass sys.modules.
00492         import os
00494         def foo():
00495             import os
00496             return os
00497         self.assertEqual(foo(), os)  # Quick sanity check.
00499         with swap_attr(builtins, "__import__", lambda *x: 5):
00500             self.assertEqual(foo(), 5)
00502         # Test what happens when we shadow __import__ in globals(); this
00503         # currently does not impact the import process, but if this changes,
00504         # other code will need to change, so keep this test as a tripwire.
00505         with swap_item(globals(), "__import__", lambda *x: 5):
00506             self.assertEqual(foo(), os)

Here is the call graph for this function:

The documentation for this class was generated from the following file: