From c8558d8d3b6c2cae273637ccec616489c2e7b439 Mon Sep 17 00:00:00 2001 From: Lennart Regebro Date: Tue, 21 Aug 2012 17:29:47 +0200 Subject: Add failing test for #301. --HG-- branch : distribute extra : rebase_source : 2972e762cdab88e90c1c8b9b9a336afc641e996f --- setuptools/command/test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index b7aef969..59c10e84 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -141,9 +141,10 @@ class test(Command): import unittest loader_ep = EntryPoint.parse("x="+self.test_loader) loader_class = loader_ep.load(require=False) + cks = loader_class() unittest.main( None, None, [unittest.__file__]+self.test_args, - testLoader = loader_class() + testLoader = cks ) -- cgit v1.2.1 From 9dc9fea4a5661e119f30f4cdec3ef99e46b5f919 Mon Sep 17 00:00:00 2001 From: Lennart Regebro Date: Wed, 22 Aug 2012 12:32:11 +0200 Subject: Issue #306: Even if 2to3 is used, we build in-place under Python 2. --HG-- branch : distribute extra : rebase_source : db4a1a3059533ad0c894f12c31e3fe1c238f4292 --- setuptools/command/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 59c10e84..e5cb9bb5 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -81,7 +81,7 @@ class test(Command): def with_project_on_sys_path(self, func): - if getattr(self.distribution, 'use_2to3', False): + if sys.version_info >= (3,) and getattr(self.distribution, 'use_2to3', False): # If we run 2to3 we can not do this inplace: # Ensure metadata is up-to-date -- cgit v1.2.1 From 077a69aef0973333cafe4c7548dceb5418d1c36f Mon Sep 17 00:00:00 2001 From: "Stefan H. Holek" Date: Mon, 8 Oct 2012 13:29:03 +0200 Subject: Purge modules under test from sys.modules prior to running tests. Fixes #301. --HG-- branch : distribute extra : rebase_source : 87561670c15ec8315f47157cdc0c06328ce8c20f --- setuptools/command/test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'setuptools/command/test.py') 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() -- cgit v1.2.1