diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-06-17 11:52:56 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-06-17 11:52:56 (GMT) |
commit | 723993983a8227d7f068b072657caa2b75d4413c (patch) | |
tree | 3a1c02fbce7ffd6e3e572157f5f8e01ad280750f /Lib/packaging | |
parent | 0f270b2c37efd2c9600d9f8648918d9b3479dd94 (diff) | |
download | cpython-723993983a8227d7f068b072657caa2b75d4413c.zip cpython-723993983a8227d7f068b072657caa2b75d4413c.tar.gz cpython-723993983a8227d7f068b072657caa2b75d4413c.tar.bz2 |
Issue #12333: run tests on the new module in a subprocess
It is not possible to unload a module written in C, so use a subprocess to run
the tests on the module compiled by test_build_ext(). Using a subprocess, we
don't have to unload the module, save/restore sys.path, and the test can be run
more than once.
This commit fixes also an access error on rmtree() on Windows: because the
module was not really unloaded, it was not possible to remove the temporary
directory (it is not possible to remove a directory on Windows if it still
contains an open file).
Diffstat (limited to 'Lib/packaging')
-rw-r--r-- | Lib/packaging/tests/test_command_build_ext.py | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/Lib/packaging/tests/test_command_build_ext.py b/Lib/packaging/tests/test_command_build_ext.py index 9729559..13bfeea5 100644 --- a/Lib/packaging/tests/test_command_build_ext.py +++ b/Lib/packaging/tests/test_command_build_ext.py @@ -8,13 +8,10 @@ from packaging.dist import Distribution from packaging.errors import UnknownFileError, CompileError from packaging.command.build_ext import build_ext from packaging.compiler.extension import Extension +from test.script_helper import assert_python_ok from packaging.tests import support, unittest, verbose, unload -# http://bugs.python.org/issue4373 -# Don't load the xx module more than once. -ALREADY_TESTED = False - def _get_source_filename(): srcdir = sysconfig.get_config_var('srcdir') @@ -29,8 +26,6 @@ class BuildExtTestCase(support.TempdirManager, # Note that we're making changes to sys.path super(BuildExtTestCase, self).setUp() self.tmp_dir = self.mkdtemp() - self.sys_path = sys.path, sys.path[:] - sys.path.append(self.tmp_dir) filename = _get_source_filename() if os.path.exists(filename): shutil.copy(filename, self.tmp_dir) @@ -58,7 +53,6 @@ class BuildExtTestCase(support.TempdirManager, cmd.library_dirs = value.split(os.pathsep) def test_build_ext(self): - global ALREADY_TESTED xx_c = os.path.join(self.tmp_dir, 'xxmodule.c') if not os.path.exists(xx_c): # skipping if we cannot find it @@ -86,29 +80,27 @@ class BuildExtTestCase(support.TempdirManager, finally: sys.stdout = old_stdout - if ALREADY_TESTED: - return - else: - ALREADY_TESTED = True + code = """if 1: + import sys + sys.path.insert(0, %r) - import xx + import xx - for attr in ('error', 'foo', 'new', 'roj'): - self.assertTrue(hasattr(xx, attr)) + for attr in ('error', 'foo', 'new', 'roj'): + assert hasattr(xx, attr) - self.assertEqual(xx.foo(2, 5), 7) - self.assertEqual(xx.foo(13, 15), 28) - self.assertEqual(xx.new().demo(), None) - doc = 'This is a template module just for instruction.' - self.assertEqual(xx.__doc__, doc) - self.assertTrue(isinstance(xx.Null(), xx.Null)) - self.assertTrue(isinstance(xx.Str(), xx.Str)) + assert xx.foo(2, 5) == 7 + assert xx.foo(13, 15) == 28 + assert xx.new().demo() is None + doc = 'This is a template module just for instruction.' + assert xx.__doc__ == doc + assert isinstance(xx.Null(), xx.Null) + assert isinstance(xx.Str(), xx.Str)""" + code = code % self.tmp_dir + assert_python_ok('-c', code) def tearDown(self): # Get everything back to normal - unload('xx') - sys.path = self.sys_path[0] - sys.path[:] = self.sys_path[1] if sys.version > "2.6": site.USER_BASE = self.old_user_base build_ext.USER_BASE = self.old_user_base |