Imported Upstream version 36.7.2 upstream/36.7.2
authorDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 14 Jan 2019 01:36:40 +0000 (10:36 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 14 Jan 2019 01:36:40 +0000 (10:36 +0900)
CHANGES.rst
setup.cfg
setup.py
setuptools/command/test.py
setuptools/tests/test_test.py

index f17e79c..9b84cdc 100644 (file)
@@ -1,3 +1,8 @@
+v36.7.2
+-------
+
+* #701: Fixed duplicate test discovery on Python 3.
+
 v36.7.1
 -------
 
index d1d94cd..f064fcf 100755 (executable)
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
 [bumpversion]
-current_version = 36.7.1
+current_version = 36.7.2
 commit = True
 tag = True
 
index 2c4ba84..7148962 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -89,7 +89,7 @@ def pypi_link(pkg_filename):
 
 setup_params = dict(
     name="setuptools",
-    version="36.7.1",
+    version="36.7.2",
     description="Easily download, build, install, upgrade, and uninstall "
         "Python packages",
     author="Python Packaging Authority",
index 638d0c5..bfa7149 100644 (file)
@@ -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,6 +110,8 @@ class test(Command):
         return list(self._test_args())
 
     def _test_args(self):
+        if not self.test_suite and sys.version_info >= (2, 7):
+            yield 'discover'
         if self.verbose:
             yield '--verbose'
         if self.test_suite:
index 7ea43c5..960527b 100644 (file)
@@ -2,9 +2,9 @@
 
 from __future__ import unicode_literals
 
+from distutils import log
 import os
-import site
-from distutils.errors import DistutilsError
+import sys
 
 import pytest
 
@@ -66,26 +66,66 @@ def sample_test(tmpdir_cwd):
         f.write(TEST_PY)
 
 
-@pytest.mark.skipif('hasattr(sys, "real_prefix")')
-@pytest.mark.usefixtures('user_override')
-@pytest.mark.usefixtures('sample_test')
-class TestTestTest:
-    def test_test(self):
-        params = dict(
-            name='foo',
-            packages=['name', 'name.space', 'name.space.tests'],
-            namespace_packages=['name'],
-            test_suite='name.space.tests.test_suite',
-            use_2to3=True,
-        )
-        dist = Distribution(params)
-        dist.script_name = 'setup.py'
-        cmd = test(dist)
-        cmd.user = 1
-        cmd.ensure_finalized()
-        cmd.install_dir = site.USER_SITE
-        cmd.user = 1
-        with contexts.quiet():
-            # The test runner calls sys.exit
-            with contexts.suppress_exceptions(SystemExit):
-                cmd.run()
+@pytest.fixture
+def quiet_log():
+    # Running some of the other tests will automatically
+    # change the log level to info, messing our output.
+    log.set_verbosity(0)
+
+
+@pytest.mark.usefixtures('sample_test', 'quiet_log')
+def test_test(capfd):
+    params = dict(
+        name='foo',
+        packages=['name', 'name.space', 'name.space.tests'],
+        namespace_packages=['name'],
+        test_suite='name.space.tests.test_suite',
+        use_2to3=True,
+    )
+    dist = Distribution(params)
+    dist.script_name = 'setup.py'
+    cmd = test(dist)
+    cmd.ensure_finalized()
+    # The test runner calls sys.exit
+    with contexts.suppress_exceptions(SystemExit):
+        cmd.run()
+    out, err = capfd.readouterr()
+    assert out == 'Foo\n'
+
+
+@pytest.mark.xfail(
+    sys.version_info < (2, 7),
+    reason="No discover support for unittest on Python 2.6",
+)
+@pytest.mark.usefixtures('tmpdir_cwd', 'quiet_log')
+def test_tests_are_run_once(capfd):
+    params = dict(
+        name='foo',
+        packages=['dummy'],
+    )
+    with open('setup.py', 'wt') as f:
+        f.write('from setuptools import setup; setup(\n')
+        for k, v in sorted(params.items()):
+            f.write('    %s=%r,\n' % (k, v))
+        f.write(')\n')
+    os.makedirs('dummy')
+    with open('dummy/__init__.py', 'wt'):
+        pass
+    with open('dummy/test_dummy.py', 'wt') as f:
+        f.write(DALS(
+            """
+            from __future__ import print_function
+            import unittest
+            class TestTest(unittest.TestCase):
+                def test_test(self):
+                    print('Foo')
+             """))
+    dist = Distribution(params)
+    dist.script_name = 'setup.py'
+    cmd = test(dist)
+    cmd.ensure_finalized()
+    # The test runner calls sys.exit
+    with contexts.suppress_exceptions(SystemExit):
+        cmd.run()
+    out, err = capfd.readouterr()
+    assert out == 'Foo\n'