Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86701
| From | Tal Einat <taleinat@gmail.com> |
|---|---|
| Date | 2015-03-02 10:08 +0200 |
| Subject | reload a module imported with importlib.machinery.SourceFileLoader |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.13.1425283723.13471.python-list@python.org> (permalink) |
Hi everyone,
I'm trying to import a module with tests, run the tests, then patch
some things with mock.patch, reload the tests module and re-run the
tests. This is part of an interactive course in which the tests module
is written by the user. Therefore I'm using
importlib.machinery.SourceFileLoader to import the tests module, like
so:
importlib.machinery.SourceFileLoader("tmp", path).load_module("tmp")
This works just fine. However, when trying to reload the module,
importlib.reload(module) is raising the following exception:
Traceback (most recent call last):
File ".../tests.py", line 28, in <module>
reload_module(module)
File ".../custom_test_helpers.py", line 18, in reload_module
importlib.reload(module)
File ".../lib/python3.4/importlib/__init__.py", line 149, in reload
methods.exec(module)
File "<frozen importlib._bootstrap>", line 1134, in exec
AttributeError: 'NoneType' object has no attribute 'name'
Am I going about this the wrong way? Is this a bug in importlib? If it
is a bug, and suggestions for a workaround?
I'm running Python 3.4.2, installed via pyenv on OSX 10.8.
- Tal Einat
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
reload a module imported with importlib.machinery.SourceFileLoader Tal Einat <taleinat@gmail.com> - 2015-03-02 10:08 +0200
csiph-web