summaryrefslogtreecommitdiff
path: root/setuptools/command
diff options
context:
space:
mode:
authorphillip.eby <phillip.eby@6015fed2-1504-0410-9fe1-9d1591cc4771>2007-02-24 22:09:20 +0000
committerphillip.eby <phillip.eby@6015fed2-1504-0410-9fe1-9d1591cc4771>2007-02-24 22:09:20 +0000
commit69a6935ac9ed307a5fa3ed6464d3a028495d1ad2 (patch)
tree4a15cf1e7f6ed9099fc896f1465777b32eddc596 /setuptools/command
parenta16c9820d87a010ae4733e38bd36233da0541e69 (diff)
downloadpython-setuptools-69a6935ac9ed307a5fa3ed6464d3a028495d1ad2.tar.gz
Fix "test" command possibly failing if an older version of the project
being tested is installed on sys.path ahead of the test source directory. git-svn-id: http://svn.python.org/projects/sandbox/trunk/setuptools@53895 6015fed2-1504-0410-9fe1-9d1591cc4771
Diffstat (limited to 'setuptools/command')
-rw-r--r--setuptools/command/test.py67
1 files changed, 56 insertions, 11 deletions
diff --git a/setuptools/command/test.py b/setuptools/command/test.py
index 01fca35..fe024c6 100644
--- a/setuptools/command/test.py
+++ b/setuptools/command/test.py
@@ -80,7 +80,7 @@ class test(Command):
- def run(self):
+ def with_project_on_sys_path(self, func):
# Ensure metadata is up-to-date
self.run_command('egg_info')
@@ -88,6 +88,24 @@ class test(Command):
self.reinitialize_command('build_ext', inplace=1)
self.run_command('build_ext')
+ 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)
@@ -97,23 +115,50 @@ class test(Command):
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(
None, None, [unittest.__file__]+self.test_args,
testLoader = loader_class()
)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+