Created
January 15, 2015 15:50
-
-
Save collinanderson/6675dc9fdc0b84d80a49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import importlib | |
import os | |
import shutil | |
testmod = os.path.join(os.path.dirname(__file__), 'testmod') | |
os.mkdir(testmod) | |
with open(os.path.join(testmod, '__init__.py'), 'w') as f: | |
f.write('pass') | |
mod1 = os.path.join(testmod, 'mod1') | |
os.mkdir(mod1) | |
with open(os.path.join(mod1, '__init__.py'), 'w') as f: | |
f.write('pass') | |
importlib.import_module('testmod.mod1') | |
mod2 = os.path.join(testmod, 'mod2') | |
os.mkdir(mod2) | |
with open(os.path.join(mod2, '__init__.py'), 'w') as f: | |
f.write('pass') | |
try: | |
importlib.import_module('testmod.mod2') | |
finally: | |
shutil.rmtree(testmod) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment