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


Groups > comp.lang.python > #86701

reload a module imported with importlib.machinery.SourceFileLoader

Return-Path <taleinat@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'attribute': 0.07; 'tests.': 0.07; 'exec': 0.09; 'subject:module': 0.09; 'tests,': 0.09; 'python': 0.11; 'bug': 0.12; 'bug,': 0.16; 'exception:': 0.16; 'fine.': 0.16; 'reload': 0.16; 'workaround?': 0.16; 'module': 0.19; 'trying': 0.19; 'everyone,': 0.19; 'user.': 0.19; 'written': 0.21; 'import': 0.22; 'tests': 0.22; 'module,': 0.24; 'skip:i 40': 0.24; 'skip:" 40': 0.26; 'skip:" 20': 0.27; 'installed': 0.27; 'patch': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '"",': 0.31; 'way?': 0.31; 'file': 0.32; 'run': 0.32; 'running': 0.33; '(most': 0.33; 'to:name:python-list': 0.33; 'subject:with': 0.35; 'received:google.com': 0.35; 'raising': 0.36; 'wrong': 0.37; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'course': 0.61; 'therefore': 0.72
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=s+jS79ensjhBIBe6y1BQPN41eIDgDoYludNtHqOaNYM=; b=V0kdkCHJj9ZCICRfhHVHkZVrrXx6U/5JYpLVidF1/4NlnmP6pARdblMLKyf8smodEv gSxZbpuK4Sl9m35F1ObTaW2dZYrX7bIVmW5bmy1GZyQ3xNds6rFtluAGKWoq6jv4pOGH AHzWw3kxouAR8wC0jAiTR/Nt50EHE8ZrPxSKJ32bRAlLT/hmhvEhRAhxYmt/Y5lYY4EF 5WZ/okGYx6uBHhV8vf0MKckW619do0izWX+9EtMb80AVUr6S8FmvsakfGWnDyM3Qo7+s PaGIM92Z1dfq6cSUCwhsSpup0wg/ewLoOSVFeJBu0QL5XL2pKIk1X3/J48eEDNuotkWc h62A==
X-Received by 10.66.182.166 with SMTP id ef6mr44516627pac.77.1425283714193; Mon, 02 Mar 2015 00:08:34 -0800 (PST)
MIME-Version 1.0
From Tal Einat <taleinat@gmail.com>
Date Mon, 2 Mar 2015 10:08:14 +0200
Subject reload a module imported with importlib.machinery.SourceFileLoader
To python-list <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.19
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.13.1425283723.13471.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1425283723 news.xs4all.nl 2978 [2001:888:2000:d::a6]:45478
X-Complaints-To abuse@xs4all.nl
Path csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:86701

Show key headers only | View raw


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


Thread

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

csiph-web