diff options
author | Stefan H. Holek <stefan@epy.co.at> | 2012-10-08 13:29:03 +0200 |
---|---|---|
committer | Stefan H. Holek <stefan@epy.co.at> | 2012-10-08 13:29:03 +0200 |
commit | 077a69aef0973333cafe4c7548dceb5418d1c36f (patch) | |
tree | 568952d46aaccb249dccab729cbb94c39fdadfae | |
parent | 71ae17459b9f3c64833e0c197b130e8dcbe1f45b (diff) | |
download | external_python_setuptools-077a69aef0973333cafe4c7548dceb5418d1c36f.tar.gz external_python_setuptools-077a69aef0973333cafe4c7548dceb5418d1c36f.tar.bz2 external_python_setuptools-077a69aef0973333cafe4c7548dceb5418d1c36f.zip |
Purge modules under test from sys.modules prior to running tests. Fixes #301.
--HG--
branch : distribute
extra : rebase_source : 87561670c15ec8315f47157cdc0c06328ce8c20f
-rw-r--r-- | setuptools/command/test.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/setuptools/command/test.py b/setuptools/command/test.py index e5cb9bb5..a02ac142 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -2,6 +2,7 @@ from setuptools import Command from distutils.errors import DistutilsOptionError import sys from pkg_resources import * +from pkg_resources import _namespace_packages from unittest import TestLoader, main class ScanningLoader(TestLoader): @@ -139,6 +140,22 @@ class test(Command): def run_tests(self): import unittest + + # Purge modules under test from sys.modules. The test loader will + # re-import them from the build location. Required when 2to3 is used + # with namespace packages. + if sys.version_info >= (3,) and getattr(self.distribution, 'use_2to3', False): + module = self.test_args[-1].split('.')[0] + if module in _namespace_packages: + del_modules = [] + if module in sys.modules: + del_modules.append(module) + module += '.' + for name in sys.modules: + if name.startswith(module): + del_modules.append(name) + map(sys.modules.__delitem__, del_modules) + loader_ep = EntryPoint.parse("x="+self.test_loader) loader_class = loader_ep.load(require=False) cks = loader_class() |