From 8423e1ed14ac1691c2863c6e8cac9230cf558d7b Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 19 Mar 2004 20:53:14 +0000 Subject: Initial checkin of setuptools 0.0.1. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4040869 --- setuptools/command/test.py | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 setuptools/command/test.py (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py new file mode 100644 index 00000000..6b37a9fd --- /dev/null +++ b/setuptools/command/test.py @@ -0,0 +1,82 @@ +from distutils.cmd import Command +from distutils.errors import DistutilsOptionError +import sys + +class test(Command): + + """Command to run unit tests after installation""" + + description = "run unit tests after installation" + + user_options = [ + ('test-module=','m', "Run 'test_suite' in specified module"), + ('test-suite=','s', + "Test suite to run (e.g. 'some_module.test_suite')"), + ] + + test_suite = None + test_module = None + + def initialize_options(self): + pass + + + def finalize_options(self): + + if self.test_suite is None: + if self.test_module is None: + self.test_suite = self.distribution.test_suite + else: + self.test_suite = self.test_module+".test_suite" + elif self.test_module: + raise DistutilsOptionError( + "You may specify a module or a suite, but not both" + ) + + self.test_args = [self.test_suite] + + if self.verbose: + self.test_args.insert(0,'--verbose') + + + def run(self): + + # Install before testing + self.run_command('install') + + if self.test_suite: + cmd = ' '.join(self.test_args) + + if self.dry_run: + self.announce('skipping "unittest %s" (dry run)' % cmd) + else: + self.announce('running "unittest %s"' % cmd) + import unittest + unittest.main(None, None, [unittest.__file__]+self.test_args) + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.1 From 3686c4d8453202853aa670f2693c7594db179c64 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Wed, 6 Jul 2005 01:54:08 +0000 Subject: Enhanced the ``test`` command so that it doesn't install the package, but instead builds any C extensions in-place, updates the ``.egg-info`` metadata, adds the source directory to ``sys.path``, and runs the tests directly on the source. This avoids an "unmanaged" installation of the package to ``site-packages`` or elsewhere. (Also, fix a breaking test of older dependency support; this should probably be removed altogether, as long as nobody's using it.) --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041078 --- setuptools/command/test.py | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 6b37a9fd..37aeac68 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -1,4 +1,4 @@ -from distutils.cmd import Command +from setuptools import Command from distutils.errors import DistutilsOptionError import sys @@ -40,35 +40,35 @@ class test(Command): def run(self): + # Ensure metadata is up-to-date + self.run_command('egg_info') - # Install before testing - self.run_command('install') + # Build extensions in-place + self.reinitialize_command('build_ext', inplace=1) + self.run_command('build_ext') if self.test_suite: cmd = ' '.join(self.test_args) - if self.dry_run: self.announce('skipping "unittest %s" (dry run)' % cmd) else: self.announce('running "unittest %s"' % cmd) - import unittest - unittest.main(None, None, [unittest.__file__]+self.test_args) - - - - - - - - - - - - - - - - + self.run_tests() + + def run_tests(self): + import unittest, pkg_resources + old_path = sys.path[:] + ei_cmd = self.get_finalized_command("egg_info") + try: + # put the egg on sys.path, and require() it + sys.path.insert(0, ei_cmd.egg_base) + pkg_resources.require( + "%s==%s" % (ei_cmd.egg_name, ei_cmd.egg_version) + ) + unittest.main(None, None, [unittest.__file__]+self.test_args) + finally: + sys.path[:] = old_path + # XXX later this might need to save/restore the WorkingSet -- cgit v1.2.1 From e5eac13db392f851f15e014a1c20debb22da89b2 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Wed, 6 Jul 2005 03:46:16 +0000 Subject: Added ``develop`` command to ``setuptools``-based packages. This command installs an ``.egg-link`` pointing to the package's source directory, and script wrappers that ``execfile()`` the source versions of the package's scripts. This lets you put your development checkout(s) on sys.path without having to actually install them. (To uninstall the link, use use ``setup.py develop --uninstall``.) --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041080 --- setuptools/command/test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 37aeac68..2b0d9484 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -4,9 +4,9 @@ import sys class test(Command): - """Command to run unit tests after installation""" + """Command to run unit tests after in-place build""" - description = "run unit tests after installation" + description = "run unit tests after in-place build" user_options = [ ('test-module=','m', "Run 'test_suite' in specified module"), -- cgit v1.2.1 From a462bb3f8cfdf798b62e7e4b5f06cbe56b2cedfd Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Thu, 21 Jul 2005 00:51:07 +0000 Subject: Make 'test' command work correctly with the 0.6 WorkingSet class. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041140 --- setuptools/command/test.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 2b0d9484..200d255d 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -1,6 +1,7 @@ from setuptools import Command from distutils.errors import DistutilsOptionError import sys +from pkg_resources import * class test(Command): @@ -38,7 +39,6 @@ class test(Command): if self.verbose: self.test_args.insert(0,'--verbose') - def run(self): # Ensure metadata is up-to-date self.run_command('egg_info') @@ -56,19 +56,19 @@ class test(Command): self.run_tests() def run_tests(self): - import unittest, pkg_resources + import unittest old_path = sys.path[:] ei_cmd = self.get_finalized_command("egg_info") - try: - # put the egg on sys.path, and require() it - sys.path.insert(0, ei_cmd.egg_base) - pkg_resources.require( - "%s==%s" % (ei_cmd.egg_name, ei_cmd.egg_version) - ) - unittest.main(None, None, [unittest.__file__]+self.test_args) - finally: - sys.path[:] = old_path - # XXX later this might need to save/restore the WorkingSet + 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())) + unittest.main(None, None, [unittest.__file__]+self.test_args) + + -- cgit v1.2.1 From 016ae6c42a868bc36c950cd3dc04e75b6ecce7dc Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sat, 19 Nov 2005 20:38:40 +0000 Subject: Added ``tests_require`` keyword to ``setup()``, so that e.g. packages requiring ``nose`` to run unit tests can make this dependency optional unless the ``test`` command is run. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041483 --- setuptools/command/test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 200d255d..31f1ae40 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -47,6 +47,9 @@ class test(Command): self.reinitialize_command('build_ext', inplace=1) self.run_command('build_ext') + if self.distribution.tests_require: + self.distribution.fetch_build_eggs(self.distribution.tests_require) + if self.test_suite: cmd = ' '.join(self.test_args) if self.dry_run: @@ -55,6 +58,7 @@ class test(Command): self.announce('running "unittest %s"' % cmd) self.run_tests() + def run_tests(self): import unittest old_path = sys.path[:] @@ -76,7 +80,3 @@ class test(Command): - - - - -- cgit v1.2.1 From fb76e7210334ecbadcabfb1549e9df40c138b746 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Tue, 28 Mar 2006 22:40:57 +0000 Subject: Enhanced test loader to scan packages as well as modules, and call ``additional_tests()`` if present to get non-unittest tests. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4043412 --- setuptools/command/test.py | 49 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 31f1ae40..30226866 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -2,6 +2,42 @@ from setuptools import Command from distutils.errors import DistutilsOptionError import sys from pkg_resources import * +from unittest import TestLoader, main + +class ScanningLoader(TestLoader): + + def loadTestsFromModule(self, module): + """Return a suite of all tests cases contained in the given module + + If the module is a package, load tests from all the modules in it. + If the module has an ``additional_tests`` function, call it and add + the return value to the tests. + """ + + tests = [TestLoader.loadTestsFromModule(self,module)] + + if hasattr(module, "additional_tests"): + tests.append(module.additional_tests()) + + if hasattr(module, '__path__'): + for file in resource_listdir(module.__name__, ''): + if file.endswith('.py') and file!='__init__.py': + submodule = module.__name__+'.'+file[:-3] + else: + if resource_exists( + module.__name__, file+'/__init__.py' + ): + submodule = module.__name__+'.'+file + else: + continue + tests.append(self.loadTestsFromName(submodule)) + + if len(tests)>1: + return self.suiteClass(tests) + else: + return tests[0] # don't create a nested suite for only one return + + class test(Command): @@ -39,6 +75,11 @@ class test(Command): if self.verbose: self.test_args.insert(0,'--verbose') + + + + + def run(self): # Ensure metadata is up-to-date self.run_command('egg_info') @@ -70,10 +111,10 @@ class test(Command): dist = Distribution(path_item, metadata, project_name=ei_cmd.egg_name) working_set.add(dist) require(str(dist.as_requirement())) - unittest.main(None, None, [unittest.__file__]+self.test_args) - - - + unittest.main( + None, None, [unittest.__file__]+self.test_args, + testLoader = ScanningLoader() + ) -- cgit v1.2.1 From 281fa7d067f8cfcf7a1a5203f03091c25c976a42 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Wed, 29 Mar 2006 21:09:43 +0000 Subject: Fix a problem with the test loader finding the bundled doctest's TestCase subclasses and trying to run them, too. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4043425 --- setuptools/command/test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 30226866..0370e372 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -13,8 +13,9 @@ class ScanningLoader(TestLoader): If the module has an ``additional_tests`` function, call it and add the return value to the tests. """ - - tests = [TestLoader.loadTestsFromModule(self,module)] + tests = [] + if module.__name__!='setuptools.tests.doctest': # ugh + tests.append(TestLoader.loadTestsFromModule(self,module)) if hasattr(module, "additional_tests"): tests.append(module.additional_tests()) @@ -32,13 +33,12 @@ class ScanningLoader(TestLoader): continue tests.append(self.loadTestsFromName(submodule)) - if len(tests)>1: + if len(tests)!=1: return self.suiteClass(tests) else: return tests[0] # don't create a nested suite for only one return - class test(Command): """Command to run unit tests after in-place build""" -- cgit v1.2.1 From 696739a1fc24ccb3ace56a2156b7199f6b85e194 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Wed, 29 Mar 2006 23:32:41 +0000 Subject: Added ``test_loader`` keyword to support custom test loaders. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4043430 --- setuptools/command/test.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 0370e372..83589fa9 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -51,11 +51,10 @@ class test(Command): "Test suite to run (e.g. 'some_module.test_suite')"), ] - test_suite = None - test_module = None - def initialize_options(self): - pass + self.test_suite = None + self.test_module = None + self.test_loader = None def finalize_options(self): @@ -74,9 +73,10 @@ class test(Command): if self.verbose: self.test_args.insert(0,'--verbose') - - - + if self.test_loader is None: + self.test_loader = getattr(self.distribution,'test_loader',None) + if self.test_loader is None: + self.test_loader = "setuptools.command.test:ScanningLoader" @@ -111,13 +111,13 @@ class test(Command): 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 = ScanningLoader() + testLoader = loader_class() ) - - -- cgit v1.2.1 From 34eb083f0db12e97f966f9312d23f07ddf962116 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sat, 24 Feb 2007 22:11:47 +0000 Subject: 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) --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4053896 --- setuptools/command/test.py | 65 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 12 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 83589fa9..fe024c60 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,7 +88,25 @@ class test(Command): 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 @@ 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( @@ -121,3 +133,32 @@ class test(Command): + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.1 From 08f3761c19825414ef0d33f584a667444ccb5523 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 2 Mar 2007 01:23:32 +0000 Subject: Fix problem activating dependencies for tests (backport from trunk) --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4054072 --- 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 fe024c60..f8a1169f 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -96,6 +96,7 @@ class test(Command): try: sys.path.insert(0, normalize_path(ei_cmd.egg_base)) working_set.__init__() + add_activation_listener(lambda dist: dist.activate()) require('%s==%s' % (ei_cmd.egg_name, ei_cmd.egg_version)) func() finally: @@ -120,7 +121,6 @@ class test(Command): - def run_tests(self): import unittest loader_ep = EntryPoint.parse("x="+self.test_loader) -- cgit v1.2.1 From 60cf2d31c8edb39b418f522ad935320c6da9c927 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Sat, 19 Jan 2008 02:55:03 +0000 Subject: Fix interactions between the various "require" options, so that downloads aren't repeated and needed eggs are always installed, even if they were downloaded to the setup directory already. (backport from trunk) --HG-- branch : setuptools-0.6 extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/branches/setuptools-0.6%4060066 --- setuptools/command/test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index f8a1169f..db918dae 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -107,6 +107,8 @@ class test(Command): def run(self): + if self.distribution.install_requires: + self.distribution.fetch_build_eggs(self.distribution.install_requires) if self.distribution.tests_require: self.distribution.fetch_build_eggs(self.distribution.tests_require) @@ -119,8 +121,6 @@ class test(Command): self.with_project_on_sys_path(self.run_tests) - - def run_tests(self): import unittest loader_ep = EntryPoint.parse("x="+self.test_loader) -- cgit v1.2.1 From 3736fee0faddbbc93fa6b7a1b233d4c2dcf11d76 Mon Sep 17 00:00:00 2001 From: Lennart Regebro Date: Fri, 18 Sep 2009 17:22:17 +0200 Subject: Works with zope.interface now. --HG-- branch : distribute extra : rebase_source : c8cd9fd837bbac96c8949f0015d84051bd8ab5c7 --- setuptools/command/test.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index db918dae..0f96e83a 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -1,4 +1,4 @@ -from setuptools import Command +from setuptools import Command, run_2to3 from distutils.errors import DistutilsOptionError import sys from pkg_resources import * @@ -81,12 +81,28 @@ class test(Command): def with_project_on_sys_path(self, func): - # Ensure metadata is up-to-date - self.run_command('egg_info') + if getattr(self.distribution, 'run_2to3', run_2to3): + # If we run 2to3 we can not do this inplace: - # Build extensions in-place - self.reinitialize_command('build_ext', inplace=1) - self.run_command('build_ext') + # Ensure metadata is up-to-date + self.reinitialize_command('build_py', inplace=0) + self.run_command('build_py') + bpy_cmd = self.get_finalized_command("build_py") + build_path = normalize_path(bpy_cmd.build_lib) + + # Build extensions + self.reinitialize_command('egg_info', egg_base=build_path) + self.run_command('egg_info') + + self.reinitialize_command('build_ext', inplace=0) + self.run_command('build_ext') + else: + # Without 2to3 inplace works fine: + self.run_command('egg_info') + + # Build extensions in-place + self.reinitialize_command('build_ext', inplace=1) + self.run_command('build_ext') ei_cmd = self.get_finalized_command("egg_info") -- cgit v1.2.1 From 7596dc0cf93965df85e36dcbca683270f5e9ded2 Mon Sep 17 00:00:00 2001 From: Lennart Regebro Date: Tue, 22 Sep 2009 17:25:53 +0200 Subject: Name changes of the parameters. --HG-- branch : distribute extra : rebase_source : fc921b526cda13b02a4bb0215f91ee04d03dca57 --- setuptools/command/test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 0f96e83a..b7aef969 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -1,4 +1,4 @@ -from setuptools import Command, run_2to3 +from setuptools import Command from distutils.errors import DistutilsOptionError import sys from pkg_resources import * @@ -81,7 +81,7 @@ class test(Command): def with_project_on_sys_path(self, func): - if getattr(self.distribution, 'run_2to3', run_2to3): + if 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 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 From 744a61f18bbfcbf7dfaa08886185b4595d8b7bcb Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Mon, 17 Jun 2013 19:23:33 +0100 Subject: Misc. updates following 2to3 checks. --HG-- branch : single-codebase --- 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 a02ac142..db2fc7b1 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -154,7 +154,7 @@ class test(Command): for name in sys.modules: if name.startswith(module): del_modules.append(name) - map(sys.modules.__delitem__, del_modules) + list(map(sys.modules.__delitem__, del_modules)) loader_ep = EntryPoint.parse("x="+self.test_loader) loader_class = loader_ep.load(require=False) -- cgit v1.2.1 From 4dcbe9cd38e5143431541c66d5dba418b665bb5a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 9 Feb 2014 18:32:28 -0500 Subject: Remove unused import and excess whitespace. --- setuptools/command/test.py | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index db2fc7b1..e936418d 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -3,7 +3,7 @@ from distutils.errors import DistutilsOptionError import sys from pkg_resources import * from pkg_resources import _namespace_packages -from unittest import TestLoader, main +from unittest import TestLoader class ScanningLoader(TestLoader): @@ -57,7 +57,6 @@ class test(Command): self.test_module = None self.test_loader = None - def finalize_options(self): if self.test_suite is None: @@ -79,8 +78,6 @@ class test(Command): if self.test_loader is None: self.test_loader = "setuptools.command.test:ScanningLoader" - - def with_project_on_sys_path(self, func): if sys.version_info >= (3,) and getattr(self.distribution, 'use_2to3', False): # If we run 2to3 we can not do this inplace: @@ -122,7 +119,6 @@ class test(Command): sys.modules.update(old_modules) working_set.__init__() - def run(self): if self.distribution.install_requires: self.distribution.fetch_build_eggs(self.distribution.install_requires) @@ -137,7 +133,6 @@ class test(Command): self.announce('running "unittest %s"' % cmd) self.with_project_on_sys_path(self.run_tests) - def run_tests(self): import unittest @@ -163,36 +158,3 @@ class test(Command): None, None, [unittest.__file__]+self.test_args, testLoader = cks ) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.1 From c20ed4dffd0779fc12c9b2fbc6433621424dbfcf Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 9 Feb 2014 18:37:09 -0500 Subject: Remove import * --- setuptools/command/test.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index e936418d..a9a0d1d7 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -1,8 +1,9 @@ from setuptools import Command from distutils.errors import DistutilsOptionError import sys -from pkg_resources import * -from pkg_resources import _namespace_packages +from pkg_resources import (resource_listdir, resource_exists, + normalize_path, working_set, _namespace_packages, add_activation_listener, + require, EntryPoint) from unittest import TestLoader class ScanningLoader(TestLoader): -- cgit v1.2.1 From 8b714dc7a9b2b74c67cd36d29e70d46fcc7f0773 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 28 Mar 2014 22:12:23 +0000 Subject: Apply patch based on patch in 2008 by Klaus Zimmerman. Fixes #176. --- setuptools/command/test.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index a9a0d1d7..24188332 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -51,12 +51,14 @@ class test(Command): ('test-module=','m', "Run 'test_suite' in specified module"), ('test-suite=','s', "Test suite to run (e.g. 'some_module.test_suite')"), + ('test-runner=', 'r', "Test runner to use"), ] def initialize_options(self): self.test_suite = None self.test_module = None self.test_loader = None + self.test_runner = None def finalize_options(self): @@ -78,6 +80,8 @@ class test(Command): self.test_loader = getattr(self.distribution,'test_loader',None) if self.test_loader is None: self.test_loader = "setuptools.command.test:ScanningLoader" + if self.test_runner is None: + self.test_runner = getattr(self.distribution, 'test_runner', None) def with_project_on_sys_path(self, func): if sys.version_info >= (3,) and getattr(self.distribution, 'use_2to3', False): @@ -154,8 +158,10 @@ class test(Command): loader_ep = EntryPoint.parse("x="+self.test_loader) loader_class = loader_ep.load(require=False) - cks = loader_class() + runner_ep = EntryPoint.parse("x=" + self.test_runner) + runner_class = runner_ep.load(require=False) unittest.main( None, None, [unittest.__file__]+self.test_args, - testLoader = cks + testLoader=loader_class(), + testRunner=runner_class(), ) -- cgit v1.2.1 From 588f3c4adf63bbd49f40ae3329da36a007f3091b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 30 Mar 2014 17:02:52 +0100 Subject: Reformat to add the conventional whitespace and shorter lines. --- setuptools/command/test.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 24188332..c46efc0f 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -16,26 +16,24 @@ class ScanningLoader(TestLoader): the return value to the tests. """ tests = [] - if module.__name__!='setuptools.tests.doctest': # ugh - tests.append(TestLoader.loadTestsFromModule(self,module)) + if module.__name__ != 'setuptools.tests.doctest': # ugh + tests.append(TestLoader.loadTestsFromModule(self, module)) if hasattr(module, "additional_tests"): tests.append(module.additional_tests()) if hasattr(module, '__path__'): for file in resource_listdir(module.__name__, ''): - if file.endswith('.py') and file!='__init__.py': - submodule = module.__name__+'.'+file[:-3] + if file.endswith('.py') and file != '__init__.py': + submodule = module.__name__ + '.' + file[:-3] else: - if resource_exists( - module.__name__, file+'/__init__.py' - ): + if resource_exists(module.__name__, file + '/__init__.py'): submodule = module.__name__+'.'+file else: continue tests.append(self.loadTestsFromName(submodule)) - if len(tests)!=1: + if len(tests) != 1: return self.suiteClass(tests) else: return tests[0] # don't create a nested suite for only one return @@ -66,7 +64,7 @@ class test(Command): if self.test_module is None: self.test_suite = self.distribution.test_suite else: - self.test_suite = self.test_module+".test_suite" + self.test_suite = self.test_module + ".test_suite" elif self.test_module: raise DistutilsOptionError( "You may specify a module or a suite, but not both" @@ -77,14 +75,18 @@ class test(Command): if self.verbose: self.test_args.insert(0,'--verbose') if self.test_loader is None: - self.test_loader = getattr(self.distribution,'test_loader',None) + self.test_loader = getattr(self.distribution, 'test_loader', None) if self.test_loader is None: self.test_loader = "setuptools.command.test:ScanningLoader" if self.test_runner is None: self.test_runner = getattr(self.distribution, 'test_runner', None) def with_project_on_sys_path(self, func): - if sys.version_info >= (3,) and getattr(self.distribution, 'use_2to3', False): + with_2to3 = ( + sys.version_info >= (3,) + and getattr(self.distribution, 'use_2to3', False) + ) + if with_2to3: # If we run 2to3 we can not do this inplace: # Ensure metadata is up-to-date -- cgit v1.2.1 From 628b5278a174d94907a25d065403feed1d2cd1d8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 30 Mar 2014 17:20:36 +0100 Subject: Extract the resolution of loader/runner classes. Allows None value to pass-through to unittest.main. Fixes #180. --- setuptools/command/test.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index c46efc0f..e377a781 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -158,12 +158,19 @@ class test(Command): del_modules.append(name) list(map(sys.modules.__delitem__, del_modules)) - loader_ep = EntryPoint.parse("x="+self.test_loader) - loader_class = loader_ep.load(require=False) - runner_ep = EntryPoint.parse("x=" + self.test_runner) - runner_class = runner_ep.load(require=False) unittest.main( None, None, [unittest.__file__]+self.test_args, - testLoader=loader_class(), - testRunner=runner_class(), + testLoader=self._resolve_as_ep(self.test_loader), + testRunner=self._resolve_as_ep(self.test_runner), ) + + @staticmethod + def _resolve_as_ep(val): + """ + Load the indicated attribute value, called, as a as if it were + specified as an entry point. + """ + if val is None: + return + parsed = EntryPoint.parse("x=" + val) + return parsed.load(require=False)() -- cgit v1.2.1 From 8b74269476d72e2e05a6f7ff35d693b816e9457c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 6 Apr 2014 18:33:37 -0400 Subject: Wrap unittest.main in a compatibility wrapper for Python 3.1 compatibility. Fixes #183 --- setuptools/command/test.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index e377a781..7422b719 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -1,10 +1,15 @@ +import unittest +from unittest import TestLoader + from setuptools import Command from distutils.errors import DistutilsOptionError import sys from pkg_resources import (resource_listdir, resource_exists, normalize_path, working_set, _namespace_packages, add_activation_listener, require, EntryPoint) -from unittest import TestLoader + +from setuptools.py31compat import unittest_main + class ScanningLoader(TestLoader): @@ -141,8 +146,6 @@ class test(Command): self.with_project_on_sys_path(self.run_tests) 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. @@ -158,7 +161,7 @@ class test(Command): del_modules.append(name) list(map(sys.modules.__delitem__, del_modules)) - unittest.main( + unittest_main( None, None, [unittest.__file__]+self.test_args, testLoader=self._resolve_as_ep(self.test_loader), testRunner=self._resolve_as_ep(self.test_runner), -- cgit v1.2.1 From 8567ca65adbf927a0af5c9b7314688dfbc46ab66 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 17 May 2014 12:25:31 -0400 Subject: Use PY3 and PY2 throughout --- setuptools/command/test.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 7422b719..3c3581a9 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -8,6 +8,7 @@ from pkg_resources import (resource_listdir, resource_exists, normalize_path, working_set, _namespace_packages, add_activation_listener, require, EntryPoint) +from setuptools.compat import PY3 from setuptools.py31compat import unittest_main @@ -87,10 +88,8 @@ class test(Command): self.test_runner = getattr(self.distribution, 'test_runner', None) def with_project_on_sys_path(self, func): - with_2to3 = ( - sys.version_info >= (3,) - and getattr(self.distribution, 'use_2to3', False) - ) + with_2to3 = PY3 and getattr(self.distribution, 'use_2to3', False) + if with_2to3: # If we run 2to3 we can not do this inplace: @@ -149,7 +148,7 @@ class test(Command): # 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): + if PY3 and getattr(self.distribution, 'use_2to3', False): module = self.test_args[-1].split('.')[0] if module in _namespace_packages: del_modules = [] -- cgit v1.2.1 From 8e3f9d3253d1d0fb820dad4249d5110d017595c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Wed, 18 Jun 2014 20:31:05 +0300 Subject: Fixed PEP 8 compliancy of the setuptools.command package --- setuptools/command/test.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 3c3581a9..18e90ffc 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -1,19 +1,17 @@ -import unittest -from unittest import TestLoader - -from setuptools import Command from distutils.errors import DistutilsOptionError +from unittest import TestLoader +import unittest import sys -from pkg_resources import (resource_listdir, resource_exists, - normalize_path, working_set, _namespace_packages, add_activation_listener, - require, EntryPoint) +from pkg_resources import (resource_listdir, resource_exists, normalize_path, + working_set, _namespace_packages, + add_activation_listener, require, EntryPoint) +from setuptools import Command from setuptools.compat import PY3 from setuptools.py31compat import unittest_main class ScanningLoader(TestLoader): - def loadTestsFromModule(self, module): """Return a suite of all tests cases contained in the given module @@ -34,7 +32,7 @@ class ScanningLoader(TestLoader): submodule = module.__name__ + '.' + file[:-3] else: if resource_exists(module.__name__, file + '/__init__.py'): - submodule = module.__name__+'.'+file + submodule = module.__name__ + '.' + file else: continue tests.append(self.loadTestsFromName(submodule)) @@ -42,19 +40,18 @@ class ScanningLoader(TestLoader): if len(tests) != 1: return self.suiteClass(tests) else: - return tests[0] # don't create a nested suite for only one return + return tests[0] # don't create a nested suite for only one return class test(Command): - """Command to run unit tests after in-place build""" description = "run unit tests after in-place build" user_options = [ - ('test-module=','m', "Run 'test_suite' in specified module"), - ('test-suite=','s', - "Test suite to run (e.g. 'some_module.test_suite')"), + ('test-module=', 'm', "Run 'test_suite' in specified module"), + ('test-suite=', 's', + "Test suite to run (e.g. 'some_module.test_suite')"), ('test-runner=', 'r', "Test runner to use"), ] @@ -79,7 +76,7 @@ class test(Command): self.test_args = [self.test_suite] if self.verbose: - self.test_args.insert(0,'--verbose') + self.test_args.insert(0, '--verbose') if self.test_loader is None: self.test_loader = getattr(self.distribution, 'test_loader', None) if self.test_loader is None: @@ -132,7 +129,8 @@ class test(Command): def run(self): if self.distribution.install_requires: - self.distribution.fetch_build_eggs(self.distribution.install_requires) + self.distribution.fetch_build_eggs( + self.distribution.install_requires) if self.distribution.tests_require: self.distribution.fetch_build_eggs(self.distribution.tests_require) @@ -161,7 +159,7 @@ class test(Command): list(map(sys.modules.__delitem__, del_modules)) unittest_main( - None, None, [unittest.__file__]+self.test_args, + None, None, [unittest.__file__] + self.test_args, testLoader=self._resolve_as_ep(self.test_loader), testRunner=self._resolve_as_ep(self.test_runner), ) -- cgit v1.2.1 From b49435397a5094f94678adf3549cc8941aa469b7 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 5 Jul 2014 15:06:51 -0400 Subject: Use six for Python 2 compatibility --HG-- branch : feature/issue-229 extra : source : 7b1997ececc5772798ce33a0f8e77387cb55a977 --- setuptools/command/test.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 1038da71..14dd2600 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -3,11 +3,12 @@ from unittest import TestLoader import unittest import sys +import six + from pkg_resources import (resource_listdir, resource_exists, normalize_path, working_set, _namespace_packages, add_activation_listener, require, EntryPoint) from setuptools import Command -from setuptools.compat import PY3 from setuptools.py31compat import unittest_main @@ -84,7 +85,7 @@ class test(Command): self.test_runner = getattr(self.distribution, 'test_runner', None) def with_project_on_sys_path(self, func): - with_2to3 = PY3 and getattr(self.distribution, 'use_2to3', False) + with_2to3 = six.PY3 and getattr(self.distribution, 'use_2to3', False) if with_2to3: # If we run 2to3 we can not do this inplace: @@ -145,7 +146,7 @@ class test(Command): # 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 PY3 and getattr(self.distribution, 'use_2to3', False): + if six.PY3 and getattr(self.distribution, 'use_2to3', False): module = self.test_args[-1].split('.')[0] if module in _namespace_packages: del_modules = [] -- cgit v1.2.1 From 26d4bb13598407c64ab1a77a33716411c5fbad3f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 5 Jul 2014 20:31:39 -0400 Subject: Remove doctests module. It is now part of Python. --- setuptools/command/test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 18e90ffc..1038da71 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -20,8 +20,7 @@ class ScanningLoader(TestLoader): the return value to the tests. """ tests = [] - if module.__name__ != 'setuptools.tests.doctest': # ugh - tests.append(TestLoader.loadTestsFromModule(self, module)) + tests.append(TestLoader.loadTestsFromModule(self, module)) if hasattr(module, "additional_tests"): tests.append(module.additional_tests()) -- cgit v1.2.1 From 80a28fa8c044ccb74e4ae54544be8c449ebd03e8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 31 Dec 2014 12:35:32 -0500 Subject: Use underlying invocation of ._load directly --- 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 1038da71..2bf5cb16 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -172,4 +172,4 @@ class test(Command): if val is None: return parsed = EntryPoint.parse("x=" + val) - return parsed.load(require=False)() + return parsed._load()() -- cgit v1.2.1 From 92a553d3adeb431cdf92b136ac9ccc3f2ef98bf1 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 5 Jan 2015 14:21:41 -0500 Subject: Add EntryPoint.resolve and deprecate most usage of EntryPoint.load. Removed EntryPoint._load. --- 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 2bf5cb16..42689f70 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -172,4 +172,4 @@ class test(Command): if val is None: return parsed = EntryPoint.parse("x=" + val) - return parsed._load()() + return parsed.resolve()() -- cgit v1.2.1 From 0a30d49169f5e73c86f452f284d10ed4b1646ff4 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 10 Oct 2015 19:59:20 -0400 Subject: Calculate test_args on demand rather than setting an attribute. --- setuptools/command/test.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 42689f70..a80d91ad 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -72,10 +72,6 @@ class test(Command): "You may specify a module or a suite, but not both" ) - self.test_args = [self.test_suite] - - if self.verbose: - self.test_args.insert(0, '--verbose') if self.test_loader is None: self.test_loader = getattr(self.distribution, 'test_loader', None) if self.test_loader is None: @@ -83,6 +79,11 @@ class test(Command): if self.test_runner is None: self.test_runner = getattr(self.distribution, 'test_runner', None) + @property + def test_args(self): + verbose = ['--verbose'] if self.verbose else [] + return verbose + [self.test_suite] + def with_project_on_sys_path(self, func): with_2to3 = PY3 and getattr(self.distribution, 'use_2to3', False) -- cgit v1.2.1 From a33e201d1a86dd108e8641f641ff24c7f00ba054 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 10 Oct 2015 20:03:33 -0400 Subject: Move value checking into its own block. --- setuptools/command/test.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index a80d91ad..4d859808 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -62,15 +62,16 @@ class test(Command): def finalize_options(self): + if self.test_suite and self.test_module: + raise DistutilsOptionError( + "You may specify a module or a suite, but not both" + ) + if self.test_suite is None: if self.test_module is None: self.test_suite = self.distribution.test_suite else: self.test_suite = self.test_module + ".test_suite" - elif self.test_module: - raise DistutilsOptionError( - "You may specify a module or a suite, but not both" - ) if self.test_loader is None: self.test_loader = getattr(self.distribution, 'test_loader', None) -- cgit v1.2.1 From 82f3e20506b4e2646880ec7ac5bb6b10e03e8c40 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 10 Oct 2015 20:03:59 -0400 Subject: Extract variable for nicer indentation --- setuptools/command/test.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 4d859808..225f4673 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -63,9 +63,8 @@ class test(Command): def finalize_options(self): if self.test_suite and self.test_module: - raise DistutilsOptionError( - "You may specify a module or a suite, but not both" - ) + msg = "You may specify a module or a suite, but not both" + raise DistutilsOptionError(msg) if self.test_suite is None: if self.test_module is None: -- cgit v1.2.1 From 552ca4d4c712c68c90601ff3f70cf4115b1636ac Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 10 Oct 2015 20:12:12 -0400 Subject: Resolve test_suite directly rather than referencing test_args --- 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 225f4673..3e9f5f72 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -147,7 +147,7 @@ class test(Command): # re-import them from the build location. Required when 2to3 is used # with namespace packages. if PY3 and getattr(self.distribution, 'use_2to3', False): - module = self.test_args[-1].split('.')[0] + module = self.test_suite.split('.')[0] if module in _namespace_packages: del_modules = [] if module in sys.modules: -- cgit v1.2.1 From 476381578991476afeca2e28a96b51fdbef50c13 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 10 Oct 2015 20:15:25 -0400 Subject: Just pass 'unittest' as argv[0] - the full path to the file shouldn't be relevant --- setuptools/command/test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 3e9f5f72..5f93d92e 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -1,6 +1,5 @@ from distutils.errors import DistutilsOptionError from unittest import TestLoader -import unittest import sys from pkg_resources import (resource_listdir, resource_exists, normalize_path, @@ -159,7 +158,7 @@ class test(Command): list(map(sys.modules.__delitem__, del_modules)) unittest_main( - None, None, [unittest.__file__] + self.test_args, + None, None, ['unittest'] + self.test_args, testLoader=self._resolve_as_ep(self.test_loader), testRunner=self._resolve_as_ep(self.test_runner), ) -- cgit v1.2.1 From 0f14cd9c52944d924c7d9ac350e4f904b0edb0af Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 10 Oct 2015 20:16:23 -0400 Subject: Extract _argv property. --- setuptools/command/test.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 5f93d92e..549cfb21 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -158,11 +158,15 @@ class test(Command): list(map(sys.modules.__delitem__, del_modules)) unittest_main( - None, None, ['unittest'] + self.test_args, + None, None, self._argv, testLoader=self._resolve_as_ep(self.test_loader), testRunner=self._resolve_as_ep(self.test_runner), ) + @property + def _argv(self): + return ['unittest'] + self.test_args + @staticmethod def _resolve_as_ep(val): """ -- cgit v1.2.1 From 9c9bfb0fc0f1f667bdabf220e939349143e0d9ec Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 10 Oct 2015 20:17:37 -0400 Subject: Re-use _argv for the announcement --- setuptools/command/test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 549cfb21..75d55bad 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -134,11 +134,11 @@ class test(Command): self.distribution.fetch_build_eggs(self.distribution.tests_require) if self.test_suite: - cmd = ' '.join(self.test_args) + cmd = ' '.join(self._argv) if self.dry_run: - self.announce('skipping "unittest %s" (dry run)' % cmd) + self.announce('skipping "%s" (dry run)' % cmd) else: - self.announce('running "unittest %s"' % cmd) + self.announce('running "%s"' % cmd) self.with_project_on_sys_path(self.run_tests) def run_tests(self): -- cgit v1.2.1 From 8223f2804628034993247add70943888d96d6348 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 10 Oct 2015 20:38:36 -0400 Subject: Only include test_suite in args if one is specified. Ref #446. --- setuptools/command/test.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 75d55bad..11e4a019 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -80,8 +80,13 @@ class test(Command): @property def test_args(self): - verbose = ['--verbose'] if self.verbose else [] - return verbose + [self.test_suite] + return list(self._test_args()) + + def _test_args(self): + if self.verbose: + yield '--verbose' + if self.test_suite: + yield self.test_suite def with_project_on_sys_path(self, func): with_2to3 = PY3 and getattr(self.distribution, 'use_2to3', False) -- cgit v1.2.1 From 5a9aed6e210628d16cd446c163fa50c9841dba34 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 10 Oct 2015 20:40:47 -0400 Subject: Accept a pattern argument, supplied by later versions of unittest. --- 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 11e4a019..13b8b46b 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -11,7 +11,7 @@ from setuptools.py31compat import unittest_main class ScanningLoader(TestLoader): - def loadTestsFromModule(self, module): + def loadTestsFromModule(self, module, pattern=None): """Return a suite of all tests cases contained in the given module If the module is a package, load tests from all the modules in it. -- cgit v1.2.1 From 34910765fbafb53bec6604b730875d010a863ae2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 10 Oct 2015 20:41:25 -0400 Subject: Always execute tests, even if no test_suite is supplied. Fixes #446. --- 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 13b8b46b..9c6a8e04 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -138,7 +138,7 @@ class test(Command): if self.distribution.tests_require: self.distribution.fetch_build_eggs(self.distribution.tests_require) - if self.test_suite: + if True: cmd = ' '.join(self._argv) if self.dry_run: self.announce('skipping "%s" (dry run)' % cmd) -- cgit v1.2.1 From 63140936955baeaf8390ddad115af1947787f37f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 10 Oct 2015 20:41:50 -0400 Subject: Remove unreachable branch. --- setuptools/command/test.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 9c6a8e04..160e21c9 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -138,13 +138,12 @@ class test(Command): if self.distribution.tests_require: self.distribution.fetch_build_eggs(self.distribution.tests_require) - if True: - cmd = ' '.join(self._argv) - if self.dry_run: - self.announce('skipping "%s" (dry run)' % cmd) - else: - self.announce('running "%s"' % cmd) - self.with_project_on_sys_path(self.run_tests) + cmd = ' '.join(self._argv) + if self.dry_run: + self.announce('skipping "%s" (dry run)' % cmd) + else: + self.announce('running "%s"' % cmd) + self.with_project_on_sys_path(self.run_tests) def run_tests(self): # Purge modules under test from sys.modules. The test loader will -- cgit v1.2.1 From a63119c9ebd8e7c578203628023877f7aa3f7e97 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 27 Nov 2015 22:41:52 -0500 Subject: Make test.test_args a non-data property per Pull Request #155. --- setuptools/command/test.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 160e21c9..c26f5fc9 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -41,6 +41,17 @@ class ScanningLoader(TestLoader): return tests[0] # don't create a nested suite for only one return +# adapted from jaraco.classes.properties:NonDataProperty +class NonDataProperty(object): + def __init__(self, fget): + self.fget = fget + + def __get__(self, obj, objtype=None): + if obj is None: + return self + return self.fget(obj) + + class test(Command): """Command to run unit tests after in-place build""" @@ -78,7 +89,7 @@ class test(Command): if self.test_runner is None: self.test_runner = getattr(self.distribution, 'test_runner', None) - @property + @NonDataProperty def test_args(self): return list(self._test_args()) -- cgit v1.2.1 From 06872bb0bbbeb953e90bd0941444b0d499056557 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 31 Dec 2015 11:51:01 -0500 Subject: Update vendoring technique to match that used for packaging. Ref #229. --HG-- branch : feature/issue-229 --- setuptools/command/test.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 5f2e2299..32ff7f15 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -2,7 +2,12 @@ from distutils.errors import DistutilsOptionError from unittest import TestLoader import sys -import six +try: + from setuptools._vendor import six +except ImportError: + # fallback to naturally-installed version; allows system packagers to + # omit vendored packages. + import six from pkg_resources import (resource_listdir, resource_exists, normalize_path, working_set, _namespace_packages, -- cgit v1.2.1 From 952c1bafda1929c74c737646aa025e6ffad6632e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 31 Dec 2015 16:30:47 -0500 Subject: Modeling after Astropy's technique for bundling libraries, the imports are now much cleaner. Thanks @embray. Ref #229. --HG-- branch : feature/issue-229 --- setuptools/command/test.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 32ff7f15..3a2a9b93 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -2,12 +2,7 @@ from distutils.errors import DistutilsOptionError from unittest import TestLoader import sys -try: - from setuptools._vendor import six -except ImportError: - # fallback to naturally-installed version; allows system packagers to - # omit vendored packages. - import six +from setuptools.extern import six from pkg_resources import (resource_listdir, resource_exists, normalize_path, working_set, _namespace_packages, -- cgit v1.2.1 From 8af3b6ef5b4173a0d0d6735147c98c882ae98344 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 16 Jan 2016 06:54:00 -0500 Subject: Always use Python 3 version of map --- setuptools/command/test.py | 1 + 1 file changed, 1 insertion(+) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 3a2a9b93..371e913b 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -3,6 +3,7 @@ from unittest import TestLoader import sys from setuptools.extern import six +from setuptools.extern.six.moves import map from pkg_resources import (resource_listdir, resource_exists, normalize_path, working_set, _namespace_packages, -- cgit v1.2.1 From e72668091ee1b8e4358a84260ac0cf0ea06b4dea Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 3 Jun 2016 09:10:19 -0400 Subject: Extract context manager for project_on_sys_path in test command --- setuptools/command/test.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 371e913b..39746a02 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -1,6 +1,7 @@ +import sys +import contextlib from distutils.errors import DistutilsOptionError from unittest import TestLoader -import sys from setuptools.extern import six from setuptools.extern.six.moves import map @@ -102,6 +103,14 @@ class test(Command): yield self.test_suite def with_project_on_sys_path(self, func): + """ + Backward compatibility for project_on_sys_path context. + """ + with self.project_on_sys_path(): + func() + + @contextlib.contextmanager + def project_on_sys_path(self): with_2to3 = six.PY3 and getattr(self.distribution, 'use_2to3', False) if with_2to3: @@ -137,7 +146,7 @@ class test(Command): working_set.__init__() add_activation_listener(lambda dist: dist.activate()) require('%s==%s' % (ei_cmd.egg_name, ei_cmd.egg_version)) - func() + yield finally: sys.path[:] = old_path sys.modules.clear() @@ -154,9 +163,11 @@ class test(Command): cmd = ' '.join(self._argv) if self.dry_run: self.announce('skipping "%s" (dry run)' % cmd) - else: - self.announce('running "%s"' % cmd) - self.with_project_on_sys_path(self.run_tests) + return + + self.announce('running "%s"' % cmd) + with self.project_on_sys_path(): + self.run_tests() def run_tests(self): # Purge modules under test from sys.modules. The test loader will -- cgit v1.2.1 From 6d11e88f938f09ef16db4c6064b6e74acba4db1d Mon Sep 17 00:00:00 2001 From: stepshal Date: Tue, 12 Jul 2016 22:00:43 +0700 Subject: Fix quantity of blank lines after code object. --- setuptools/command/test.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 39746a02..2d1adba8 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -14,6 +14,7 @@ from setuptools.py31compat import unittest_main class ScanningLoader(TestLoader): + def loadTestsFromModule(self, module, pattern=None): """Return a suite of all tests cases contained in the given module @@ -46,6 +47,7 @@ class ScanningLoader(TestLoader): # adapted from jaraco.classes.properties:NonDataProperty class NonDataProperty(object): + def __init__(self, fget): self.fget = fget -- cgit v1.2.1 From 5e4eea7d600f44321e76689890f9f885669f34c9 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 17 Sep 2016 17:05:07 -0400 Subject: In test command, add installed eggs to PYTHONPATH when invoking tests so that subprocesses will also have the dependencies available. Fixes #794. --- setuptools/command/test.py | 57 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 9 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 2d1adba8..e0650d27 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -1,10 +1,12 @@ +import os +import operator import sys import contextlib from distutils.errors import DistutilsOptionError from unittest import TestLoader from setuptools.extern import six -from setuptools.extern.six.moves import map +from setuptools.extern.six.moves import map, filter from pkg_resources import (resource_listdir, resource_exists, normalize_path, working_set, _namespace_packages, @@ -112,7 +114,7 @@ class test(Command): func() @contextlib.contextmanager - def project_on_sys_path(self): + def project_on_sys_path(self, include_dists=[]): with_2to3 = six.PY3 and getattr(self.distribution, 'use_2to3', False) if with_2to3: @@ -144,23 +146,57 @@ class test(Command): old_modules = sys.modules.copy() try: - sys.path.insert(0, normalize_path(ei_cmd.egg_base)) + project_path = normalize_path(ei_cmd.egg_base) + sys.path.insert(0, project_path) working_set.__init__() add_activation_listener(lambda dist: dist.activate()) require('%s==%s' % (ei_cmd.egg_name, ei_cmd.egg_version)) - yield + with self.paths_on_pythonpath([project_path]): + yield finally: sys.path[:] = old_path sys.modules.clear() sys.modules.update(old_modules) working_set.__init__() + @staticmethod + @contextlib.contextmanager + def paths_on_pythonpath(paths): + """ + Add the indicated paths to the head of the PYTHONPATH environment + variable so that subprocesses will also see the packages at + these paths. + + Do this in a context that restores the value on exit. + """ + nothing = object() + orig_pythonpath = os.environ.get('PYTHONPATH', nothing) + current_pythonpath = os.environ.get('PYTHONPATH', '') + try: + prefix = os.pathsep.join(paths) + to_join = filter(None, [prefix, current_pythonpath]) + new_path = os.pathsep.join(to_join) + if new_path: + os.environ['PYTHONPATH'] = new_path + yield + finally: + if orig_pythonpath is nothing: + os.environ.pop('PYTHONPATH', None) + else: + os.environ['PYTHONPATH'] = orig_pythonpath + def run(self): + installed_dists = [] if self.distribution.install_requires: - self.distribution.fetch_build_eggs( - self.distribution.install_requires) + installed_dists.extend( + self.distribution.fetch_build_eggs( + self.distribution.install_requires, + )) if self.distribution.tests_require: - self.distribution.fetch_build_eggs(self.distribution.tests_require) + installed_dists.extend( + self.distribution.fetch_build_eggs( + self.distribution.tests_require, + )) cmd = ' '.join(self._argv) if self.dry_run: @@ -168,8 +204,11 @@ class test(Command): return self.announce('running "%s"' % cmd) - with self.project_on_sys_path(): - self.run_tests() + + paths = map(operator.attrgetter('location'), installed_dists) + with self.paths_on_pythonpath(paths): + with self.project_on_sys_path(): + self.run_tests() def run_tests(self): # Purge modules under test from sys.modules. The test loader will -- cgit v1.2.1 From 2f3b7b204187a1c93c391ffac96a9220cbb57f91 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 18 Sep 2016 09:20:17 -0400 Subject: Extract test.install_dists and distill it with a variable extraction and fallback variables. --- setuptools/command/test.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index e0650d27..48d5b5e1 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -2,6 +2,7 @@ import os import operator import sys import contextlib +import itertools from distutils.errors import DistutilsOptionError from unittest import TestLoader @@ -185,18 +186,18 @@ class test(Command): else: os.environ['PYTHONPATH'] = orig_pythonpath + def install_dists(self): + """ + Install the requirements indicated by self.distribution and + return an iterable of the dists that were built. + """ + dist = self.distribution + ir_d = dist.fetch_build_eggs(dist.install_requires or []) + tr_d = dist.fetch_build_eggs(dist.tests_require or []) + return itertools.chain(ir_d, tr_d) + def run(self): - installed_dists = [] - if self.distribution.install_requires: - installed_dists.extend( - self.distribution.fetch_build_eggs( - self.distribution.install_requires, - )) - if self.distribution.tests_require: - installed_dists.extend( - self.distribution.fetch_build_eggs( - self.distribution.tests_require, - )) + installed_dists = self.install_dists() cmd = ' '.join(self._argv) if self.dry_run: -- cgit v1.2.1 From 2148592395ef4da0d408be26bf5839117ee0e5fe Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 18 Sep 2016 09:27:23 -0400 Subject: Even better, use a static method --- setuptools/command/test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 48d5b5e1..38bbcd8b 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -186,18 +186,18 @@ class test(Command): else: os.environ['PYTHONPATH'] = orig_pythonpath - def install_dists(self): + @staticmethod + def install_dists(dist): """ Install the requirements indicated by self.distribution and return an iterable of the dists that were built. """ - dist = self.distribution ir_d = dist.fetch_build_eggs(dist.install_requires or []) tr_d = dist.fetch_build_eggs(dist.tests_require or []) return itertools.chain(ir_d, tr_d) def run(self): - installed_dists = self.install_dists() + installed_dists = self.install_dists(self.distribution) cmd = ' '.join(self._argv) if self.dry_run: -- cgit v1.2.1 From 31bd37c6ac8de9e8c1bacebc2d8e1215df91eb96 Mon Sep 17 00:00:00 2001 From: stepshal Date: Tue, 18 Oct 2016 20:24:35 +0700 Subject: Fix quantity of blank lines. --- setuptools/command/test.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 38bbcd8b..270674e2 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -17,7 +17,6 @@ from setuptools.py31compat import unittest_main class ScanningLoader(TestLoader): - def loadTestsFromModule(self, module, pattern=None): """Return a suite of all tests cases contained in the given module @@ -50,7 +49,6 @@ class ScanningLoader(TestLoader): # adapted from jaraco.classes.properties:NonDataProperty class NonDataProperty(object): - def __init__(self, fget): self.fget = fget -- cgit v1.2.1 From 53b47e1dfa9dfb1e8b94172a4650409fc03d4048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 7 Dec 2016 15:00:43 +0200 Subject: Tell unittest.main not to exit, fixes #850. --- setuptools/command/test.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 270674e2..9a5117be 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -225,10 +225,12 @@ class test(Command): del_modules.append(name) list(map(sys.modules.__delitem__, del_modules)) + exit_kwarg = {} if sys.version_info < (2, 7) else {"exit": False} unittest_main( None, None, self._argv, testLoader=self._resolve_as_ep(self.test_loader), testRunner=self._resolve_as_ep(self.test_runner), + **exit_kwarg ) @property -- cgit v1.2.1 From f14930e66601b462699c44384c482cd966f53b8f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 9 Dec 2016 08:16:33 -0500 Subject: Drop support for Python 2.6, removing lots of compatibility code for a leaner, cleaner codebase. Fixes #878. --- setuptools/command/test.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 9a5117be..9931565b 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -3,6 +3,7 @@ import operator import sys import contextlib import itertools +import unittest from distutils.errors import DistutilsOptionError from unittest import TestLoader @@ -13,7 +14,6 @@ from pkg_resources import (resource_listdir, resource_exists, normalize_path, working_set, _namespace_packages, add_activation_listener, require, EntryPoint) from setuptools import Command -from setuptools.py31compat import unittest_main class ScanningLoader(TestLoader): @@ -225,12 +225,11 @@ class test(Command): del_modules.append(name) list(map(sys.modules.__delitem__, del_modules)) - exit_kwarg = {} if sys.version_info < (2, 7) else {"exit": False} - unittest_main( + unittest.main( None, None, self._argv, testLoader=self._resolve_as_ep(self.test_loader), testRunner=self._resolve_as_ep(self.test_runner), - **exit_kwarg + exit=False, ) @property -- cgit v1.2.1 From 9f37eb817df5d9453e49edbcf2760832f333af68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 16 Dec 2016 15:32:16 +0100 Subject: Exit on test failure When test fails, it should not continue to run other commands. Fixes #891 --- setuptools/command/test.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 9a5117be..60ba2354 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -226,12 +226,14 @@ class test(Command): list(map(sys.modules.__delitem__, del_modules)) exit_kwarg = {} if sys.version_info < (2, 7) else {"exit": False} - unittest_main( + test = unittest_main( None, None, self._argv, testLoader=self._resolve_as_ep(self.test_loader), testRunner=self._resolve_as_ep(self.test_runner), **exit_kwarg ) + if not test.result.wasSuccessful(): + sys.exit(1) @property def _argv(self): -- cgit v1.2.1 From 2c4fd43277fc477d85b50e15c37b176136676270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 16 Dec 2016 16:15:04 +0100 Subject: Raise DistutilsError and log result --- setuptools/command/test.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 60ba2354..ef0af12f 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -3,7 +3,8 @@ import operator import sys import contextlib import itertools -from distutils.errors import DistutilsOptionError +from distutils.errors import DistutilsError, DistutilsOptionError +from distutils import log from unittest import TestLoader from setuptools.extern import six @@ -233,7 +234,9 @@ class test(Command): **exit_kwarg ) if not test.result.wasSuccessful(): - sys.exit(1) + msg = 'Test failed: %s' % test.result + self.announce(msg, log.ERROR) + raise DistutilsError(msg) @property def _argv(self): -- cgit v1.2.1 From ff371f18f0076bc63da05334f7e551c1cc29e10d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 1 Jan 2017 22:34:28 -0500 Subject: Strip out vendored packages and require them instead. Ref #581. --- setuptools/command/test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index ef0af12f..e7a386d1 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -7,8 +7,8 @@ from distutils.errors import DistutilsError, DistutilsOptionError from distutils import log from unittest import TestLoader -from setuptools.extern import six -from setuptools.extern.six.moves import map, filter +import six +from six.moves import map, filter from pkg_resources import (resource_listdir, resource_exists, normalize_path, working_set, _namespace_packages, -- cgit v1.2.1 From 3d0cc355fb5e8012cb8c72f0e25042a5a44f31d6 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 24 Feb 2017 11:49:51 -0500 Subject: Revert "Merge pull request #933 from pypa/feature/581-depend-not-bundle" This reverts commit 089cdeb489a0fa94d11b7307b54210ef9aa40511, reversing changes made to aaec654d804cb78dbb6391afff721a63f26a71cd. --- setuptools/command/test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index e7a386d1..ef0af12f 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -7,8 +7,8 @@ from distutils.errors import DistutilsError, DistutilsOptionError from distutils import log from unittest import TestLoader -import six -from six.moves import map, filter +from setuptools.extern import six +from setuptools.extern.six.moves import map, filter from pkg_resources import (resource_listdir, resource_exists, normalize_path, working_set, _namespace_packages, -- cgit v1.2.1 From d919999bf8c37b2efad7d6eb57ec2f5ff340799e Mon Sep 17 00:00:00 2001 From: anatoly techtonik Date: Tue, 16 May 2017 11:13:30 +0300 Subject: Document -s to run single test Fixes https://github.com/pypa/setuptools/issues/1032 --- 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 e7a386d1..29227d79 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -67,7 +67,7 @@ class test(Command): user_options = [ ('test-module=', 'm', "Run 'test_suite' in specified module"), ('test-suite=', 's', - "Test suite to run (e.g. 'some_module.test_suite')"), + "Run single test, case or suite (e.g. 'module.test_suite')"), ('test-runner=', 'r', "Test runner to use"), ] -- cgit v1.2.1 From 75e88f63cc0308f7933e936b171f9cba2d04e7ad Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Fri, 21 Jul 2017 16:39:15 +0200 Subject: fix `test` command handling of `extras_require` Also install platform specific requirements in `extras_require`. --- setuptools/command/test.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index b8863fdc..638d0c56 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -11,7 +11,7 @@ from setuptools.extern import six from setuptools.extern.six.moves import map, filter from pkg_resources import (resource_listdir, resource_exists, normalize_path, - working_set, _namespace_packages, + working_set, _namespace_packages, evaluate_marker, add_activation_listener, require, EntryPoint) from setuptools import Command from setuptools.py31compat import unittest_main @@ -191,9 +191,13 @@ class test(Command): Install the requirements indicated by self.distribution and return an iterable of the dists that were built. """ - ir_d = dist.fetch_build_eggs(dist.install_requires or []) + ir_d = dist.fetch_build_eggs(dist.install_requires) tr_d = dist.fetch_build_eggs(dist.tests_require or []) - return itertools.chain(ir_d, tr_d) + er_d = dist.fetch_build_eggs( + v for k, v in dist.extras_require.items() + if k.startswith(':') and evaluate_marker(k[1:]) + ) + return itertools.chain(ir_d, tr_d, er_d) def run(self): installed_dists = self.install_dists(self.distribution) -- cgit v1.2.1 From 84093b78ec61ad47a2a0dea9f1be8d94fa0d485e Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Mon, 26 Jun 2017 16:32:43 +0200 Subject: fix `test` command when run with Python 2 When using Python 2, `python2 -m unittest` is not equivalent to `python2 -m unittest discover`. --- setuptools/command/test.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 638d0c56..523407fd 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -101,6 +101,8 @@ class test(Command): return list(self._test_args()) def _test_args(self): + if not self.test_suite: + yield 'discover' if self.verbose: yield '--verbose' if self.test_suite: -- cgit v1.2.1 From dbff2e7ed421be9ec96029366479a8627691e7f3 Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Mon, 26 Jun 2017 16:33:36 +0200 Subject: fix `test` command running tests twice --- setuptools/command/test.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 523407fd..bfa71496 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -18,6 +18,11 @@ from setuptools.py31compat import unittest_main class ScanningLoader(TestLoader): + + def __init__(self): + TestLoader.__init__(self) + self._visited = set() + def loadTestsFromModule(self, module, pattern=None): """Return a suite of all tests cases contained in the given module @@ -25,6 +30,10 @@ class ScanningLoader(TestLoader): If the module has an ``additional_tests`` function, call it and add the return value to the tests. """ + if module in self._visited: + return None + self._visited.add(module) + tests = [] tests.append(TestLoader.loadTestsFromModule(self, module)) @@ -101,7 +110,7 @@ class test(Command): return list(self._test_args()) def _test_args(self): - if not self.test_suite: + if not self.test_suite and sys.version_info >= (2, 7): yield 'discover' if self.verbose: yield '--verbose' -- cgit v1.2.1 From cca86c7f1d4040834c3265ccecdd9e21b4036df5 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 3 Jun 2018 09:50:25 -0400 Subject: Use Python 3 syntax for new-style clasess --- setuptools/command/test.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 51aee1f7..dde0118c 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -16,6 +16,8 @@ from pkg_resources import (resource_listdir, resource_exists, normalize_path, add_activation_listener, require, EntryPoint) from setuptools import Command +__metaclass__ = type + class ScanningLoader(TestLoader): @@ -58,7 +60,7 @@ class ScanningLoader(TestLoader): # adapted from jaraco.classes.properties:NonDataProperty -class NonDataProperty(object): +class NonDataProperty: def __init__(self, fget): self.fget = fget -- cgit v1.2.1 From 5b2175ebd9f4a669097e8309a53e3b843dcbb218 Mon Sep 17 00:00:00 2001 From: robnagler Date: Tue, 26 Feb 2019 17:10:49 +0000 Subject: uniquify paths in PYTHONPATH When running in a complex environment with lots of installed packages, PYTHONPATH gets way too long. Instead, just make sure that paths_on_pythonpath doesn't contain duplicates --- setuptools/command/test.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index dde0118c..997fd8b0 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -186,11 +186,12 @@ class test(Command): orig_pythonpath = os.environ.get('PYTHONPATH', nothing) current_pythonpath = os.environ.get('PYTHONPATH', '') try: - prefix = os.pathsep.join(paths) - to_join = filter(None, [prefix, current_pythonpath]) - new_path = os.pathsep.join(to_join) - if new_path: - os.environ['PYTHONPATH'] = new_path + to_join = [] + for x in list(paths) + current_pythonpath.split(os.pathsep): + if x not in to_join: + to_join.append(x) + if to_join: + os.environ['PYTHONPATH'] = os.pathsep.join(to_join) yield finally: if orig_pythonpath is nothing: -- cgit v1.2.1 From 8db41e478db4ded53b9836f62211f8c9371ec7c9 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 5 Apr 2019 15:12:21 -0400 Subject: Rely on unique_everseen to avoid unnecessarily polluting the PYTHONPATH with duplicate entries. --- setuptools/command/test.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 997fd8b0..973e4eb2 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -15,6 +15,7 @@ from pkg_resources import (resource_listdir, resource_exists, normalize_path, working_set, _namespace_packages, evaluate_marker, add_activation_listener, require, EntryPoint) from setuptools import Command +from .build_py import _unique_everseen __metaclass__ = type @@ -186,12 +187,11 @@ class test(Command): orig_pythonpath = os.environ.get('PYTHONPATH', nothing) current_pythonpath = os.environ.get('PYTHONPATH', '') try: - to_join = [] - for x in list(paths) + current_pythonpath.split(os.pathsep): - if x not in to_join: - to_join.append(x) - if to_join: - os.environ['PYTHONPATH'] = os.pathsep.join(to_join) + prefix = os.pathsep.join(_unique_everseen(paths)) + to_join = filter(None, [prefix, current_pythonpath]) + new_path = os.pathsep.join(to_join) + if new_path: + os.environ['PYTHONPATH'] = new_path yield finally: if orig_pythonpath is nothing: -- cgit v1.2.1 From cd84510713ada48bf33d4efa749c2952e3fc1a49 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 19 Oct 2019 08:39:30 -0700 Subject: Deprecate the test command Provide a warning to users. Suggest using tox as an alternative generic entry point. Refs #1684 --- setuptools/command/test.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 973e4eb2..c148b38d 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -74,7 +74,7 @@ class NonDataProperty: class test(Command): """Command to run unit tests after in-place build""" - description = "run unit tests after in-place build" + description = "run unit tests after in-place build (deprecated)" user_options = [ ('test-module=', 'm', "Run 'test_suite' in specified module"), @@ -214,6 +214,14 @@ class test(Command): return itertools.chain(ir_d, tr_d, er_d) def run(self): + self.announce( + "WARNING: Testing via this command is deprecated and will be " + "removed in a future version. Users looking for a generic test " + "entry point independent of test runner are encouraged to use " + "tox.", + log.WARN, + ) + installed_dists = self.install_dists(self.distribution) cmd = ' '.join(self._argv) -- cgit v1.2.1 From 796abd8dbec884cedf326cb5f85512a5d5648c4e Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 8 Jan 2020 19:10:11 +0200 Subject: Fix for Python 4: replace unsafe six.PY3 with PY2 --- setuptools/command/test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index c148b38d..f6470e9c 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -129,7 +129,7 @@ class test(Command): @contextlib.contextmanager def project_on_sys_path(self, include_dists=[]): - with_2to3 = six.PY3 and getattr(self.distribution, 'use_2to3', False) + with_2to3 = not six.PY2 and getattr(self.distribution, 'use_2to3', False) if with_2to3: # If we run 2to3 we can not do this inplace: @@ -240,7 +240,7 @@ class test(Command): # 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 six.PY3 and getattr(self.distribution, 'use_2to3', False): + if not six.PY2 and getattr(self.distribution, 'use_2to3', False): module = self.test_suite.split('.')[0] if module in _namespace_packages: del_modules = [] -- cgit v1.2.1 From 3d4d8b9dde61b87271861b8c7ebeb168ac4fa72b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 19 Jan 2020 12:46:30 -0500 Subject: =?UTF-8?q?=F0=9F=91=B9=20Feed=20the=20hobgoblins=20(delint).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 f6470e9c..2d83967d 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -129,7 +129,8 @@ class test(Command): @contextlib.contextmanager def project_on_sys_path(self, include_dists=[]): - with_2to3 = not six.PY2 and getattr(self.distribution, 'use_2to3', False) + with_2to3 = not six.PY2 and getattr( + self.distribution, 'use_2to3', False) if with_2to3: # If we run 2to3 we can not do this inplace: -- cgit v1.2.1 From fb7ab81a3d080422687bad71f9ae9d36eeefbee2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 16 Aug 2020 00:29:24 -0400 Subject: Remove Python 2 compatibility --- setuptools/command/test.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 2d83967d..cf71ad01 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -8,17 +8,12 @@ from distutils.errors import DistutilsError, DistutilsOptionError from distutils import log from unittest import TestLoader -from setuptools.extern import six -from setuptools.extern.six.moves import map, filter - from pkg_resources import (resource_listdir, resource_exists, normalize_path, working_set, _namespace_packages, evaluate_marker, add_activation_listener, require, EntryPoint) from setuptools import Command from .build_py import _unique_everseen -__metaclass__ = type - class ScanningLoader(TestLoader): @@ -129,8 +124,7 @@ class test(Command): @contextlib.contextmanager def project_on_sys_path(self, include_dists=[]): - with_2to3 = not six.PY2 and getattr( - self.distribution, 'use_2to3', False) + with_2to3 = getattr(self.distribution, 'use_2to3', False) if with_2to3: # If we run 2to3 we can not do this inplace: @@ -241,7 +235,7 @@ class test(Command): # 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 not six.PY2 and getattr(self.distribution, 'use_2to3', False): + if getattr(self.distribution, 'use_2to3', False): module = self.test_suite.split('.')[0] if module in _namespace_packages: del_modules = [] -- cgit v1.2.1 From 9c2cf25a13bf33a3fd706c97064c0d2fa22be179 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 22 May 2021 19:19:05 -0400 Subject: Use unique_everseen from more_itertools. --- setuptools/command/test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index cf71ad01..de4f3d11 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -12,7 +12,7 @@ from pkg_resources import (resource_listdir, resource_exists, normalize_path, working_set, _namespace_packages, evaluate_marker, add_activation_listener, require, EntryPoint) from setuptools import Command -from .build_py import _unique_everseen +from setuptools.extern.more_itertools import unique_everseen class ScanningLoader(TestLoader): @@ -182,7 +182,7 @@ class test(Command): orig_pythonpath = os.environ.get('PYTHONPATH', nothing) current_pythonpath = os.environ.get('PYTHONPATH', '') try: - prefix = os.pathsep.join(_unique_everseen(paths)) + prefix = os.pathsep.join(unique_everseen(paths)) to_join = filter(None, [prefix, current_pythonpath]) new_path = os.pathsep.join(to_join) if new_path: -- cgit v1.2.1 From ca296ca8663a376f3c36c9f8fd86b10ba81366c2 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Sun, 18 Jul 2021 09:27:21 +0100 Subject: remove lib2to3 usage --- setuptools/command/test.py | 71 ++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 46 deletions(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index de4f3d11..5e1ef57e 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -8,15 +8,22 @@ from distutils.errors import DistutilsError, DistutilsOptionError from distutils import log from unittest import TestLoader -from pkg_resources import (resource_listdir, resource_exists, normalize_path, - working_set, _namespace_packages, evaluate_marker, - add_activation_listener, require, EntryPoint) +from pkg_resources import ( + resource_listdir, + resource_exists, + normalize_path, + working_set, + _namespace_packages, + evaluate_marker, + add_activation_listener, + require, + EntryPoint, +) from setuptools import Command from setuptools.extern.more_itertools import unique_everseen class ScanningLoader(TestLoader): - def __init__(self): TestLoader.__init__(self) self._visited = set() @@ -73,8 +80,11 @@ class test(Command): user_options = [ ('test-module=', 'm', "Run 'test_suite' in specified module"), - ('test-suite=', 's', - "Run single test, case or suite (e.g. 'module.test_suite')"), + ( + 'test-suite=', + 's', + "Run single test, case or suite (e.g. 'module.test_suite')", + ), ('test-runner=', 'r', "Test runner to use"), ] @@ -124,30 +134,11 @@ class test(Command): @contextlib.contextmanager def project_on_sys_path(self, include_dists=[]): - with_2to3 = getattr(self.distribution, 'use_2to3', False) - - if with_2to3: - # If we run 2to3 we can not do this inplace: + self.run_command('egg_info') - # Ensure metadata is up-to-date - self.reinitialize_command('build_py', inplace=0) - self.run_command('build_py') - bpy_cmd = self.get_finalized_command("build_py") - build_path = normalize_path(bpy_cmd.build_lib) - - # Build extensions - self.reinitialize_command('egg_info', egg_base=build_path) - self.run_command('egg_info') - - self.reinitialize_command('build_ext', inplace=0) - self.run_command('build_ext') - else: - # Without 2to3 inplace works fine: - self.run_command('egg_info') - - # Build extensions in-place - self.reinitialize_command('build_ext', inplace=1) - self.run_command('build_ext') + # Build extensions in-place + self.reinitialize_command('build_ext', inplace=1) + self.run_command('build_ext') ei_cmd = self.get_finalized_command("egg_info") @@ -203,7 +194,8 @@ class test(Command): ir_d = dist.fetch_build_eggs(dist.install_requires) tr_d = dist.fetch_build_eggs(dist.tests_require or []) er_d = dist.fetch_build_eggs( - v for k, v in dist.extras_require.items() + v + for k, v in dist.extras_require.items() if k.startswith(':') and evaluate_marker(k[1:]) ) return itertools.chain(ir_d, tr_d, er_d) @@ -232,23 +224,10 @@ class test(Command): self.run_tests() def run_tests(self): - # 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 getattr(self.distribution, 'use_2to3', False): - module = self.test_suite.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) - list(map(sys.modules.__delitem__, del_modules)) - test = unittest.main( - None, None, self._argv, + None, + None, + self._argv, testLoader=self._resolve_as_ep(self.test_loader), testRunner=self._resolve_as_ep(self.test_runner), exit=False, -- cgit v1.2.1 From bb8a8b8578295e6632ed464f355013a01c2a05e0 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 4 Sep 2021 12:20:48 -0400 Subject: =?UTF-8?q?=F0=9F=91=B9=20Feed=20the=20hobgoblins=20(delint).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setuptools/command/test.py | 1 - 1 file changed, 1 deletion(-) (limited to 'setuptools/command/test.py') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 5e1ef57e..4a389e4d 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -13,7 +13,6 @@ from pkg_resources import ( resource_exists, normalize_path, working_set, - _namespace_packages, evaluate_marker, add_activation_listener, require, -- cgit v1.2.1