Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #86701 > unrolled thread

reload a module imported with importlib.machinery.SourceFileLoader

Started byTal Einat <taleinat@gmail.com>
First post2015-03-02 10:08 +0200
Last post2015-03-02 10:08 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  reload a module imported with importlib.machinery.SourceFileLoader Tal Einat <taleinat@gmail.com> - 2015-03-02 10:08 +0200

#86701 — reload a module imported with importlib.machinery.SourceFileLoader

FromTal Einat <taleinat@gmail.com>
Date2015-03-02 10:08 +0200
Subjectreload a module imported with importlib.machinery.SourceFileLoader
Message-ID<mailman.13.1425283723.13471.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web