[Python-checkins] r53896 - in sandbox/branches/setuptools-0.6: setuptools.txt setuptools/command/test.py
phillip.eby
python-checkins at python.org
Sat Feb 24 23:11:50 CET 2007
Author: phillip.eby
Date: Sat Feb 24 23:11:47 2007
New Revision: 53896
Modified:
sandbox/branches/setuptools-0.6/setuptools.txt
sandbox/branches/setuptools-0.6/setuptools/command/test.py
Log:
Fix ``test`` command possibly failing if an older version of the project
being tested was installed on ``sys.path`` ahead of the test source
directory. (backport from trunk)
Modified: sandbox/branches/setuptools-0.6/setuptools.txt
==============================================================================
--- sandbox/branches/setuptools-0.6/setuptools.txt (original)
+++ sandbox/branches/setuptools-0.6/setuptools.txt Sat Feb 24 23:11:47 2007
@@ -2622,6 +2622,10 @@
* Fix ``#!`` parsing problems in Windows ``.exe`` script wrappers, when there
was whitespace inside a quoted argument or at the end of the ``#!`` line
(a regression introduced in 0.6c4).
+
+ * Fix ``test`` command possibly failing if an older version of the project
+ being tested was installed on ``sys.path`` ahead of the test source
+ directory.
0.6c5
* Fix uploaded ``bdist_rpm`` packages being described as ``bdist_egg``
Modified: sandbox/branches/setuptools-0.6/setuptools/command/test.py
==============================================================================
--- sandbox/branches/setuptools-0.6/setuptools/command/test.py (original)
+++ sandbox/branches/setuptools-0.6/setuptools/command/test.py Sat Feb 24 23:11:47 2007
@@ -80,7 +80,7 @@
- def run(self):
+ def with_project_on_sys_path(self, func):
# Ensure metadata is up-to-date
self.run_command('egg_info')
@@ -88,7 +88,25 @@
self.reinitialize_command('build_ext', inplace=1)
self.run_command('build_ext')
- if self.distribution.tests_require:
+ ei_cmd = self.get_finalized_command("egg_info")
+
+ old_path = sys.path[:]
+ old_modules = sys.modules.copy()
+
+ try:
+ sys.path.insert(0, normalize_path(ei_cmd.egg_base))
+ working_set.__init__()
+ require('%s==%s' % (ei_cmd.egg_name, ei_cmd.egg_version))
+ func()
+ finally:
+ sys.path[:] = old_path
+ sys.modules.clear()
+ sys.modules.update(old_modules)
+ working_set.__init__()
+
+
+ def run(self):
+ if self.distribution.tests_require:
self.distribution.fetch_build_eggs(self.distribution.tests_require)
if self.test_suite:
@@ -97,20 +115,14 @@
self.announce('skipping "unittest %s" (dry run)' % cmd)
else:
self.announce('running "unittest %s"' % cmd)
- self.run_tests()
+ self.with_project_on_sys_path(self.run_tests)
+
+
+
def run_tests(self):
import unittest
- old_path = sys.path[:]
- ei_cmd = self.get_finalized_command("egg_info")
- path_item = normalize_path(ei_cmd.egg_base)
- metadata = PathMetadata(
- path_item, normalize_path(ei_cmd.egg_info)
- )
- dist = Distribution(path_item, metadata, project_name=ei_cmd.egg_name)
- working_set.add(dist)
- require(str(dist.as_requirement()))
loader_ep = EntryPoint.parse("x="+self.test_loader)
loader_class = loader_ep.load(require=False)
unittest.main(
@@ -121,3 +133,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
More information about the Python-checkins
mailing list