From 0216f6905d3988455e361305c6aaf98fa44d1536 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 20 Jun 2022 23:12:26 +0200 Subject: [PATCH 1/6] gh-93839: Move Lib/unttest/test/ to Lib/test/test_unittest/ * Remove Lib/test/test_unittest.py --- Lib/test/test_unittest.py | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 Lib/test/test_unittest.py diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py deleted file mode 100644 index 1079c7df2e51c2..00000000000000 --- a/Lib/test/test_unittest.py +++ /dev/null @@ -1,16 +0,0 @@ -import unittest.test - -from test import support - - -def load_tests(*_): - # used by unittest - return unittest.test.suite() - - -def tearDownModule(): - support.reap_children() - - -if __name__ == "__main__": - unittest.main() From e6f3a53e836ade11c705d68cc7ee633d702b5dad Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 20 Jun 2022 23:13:19 +0200 Subject: [PATCH 2/6] * Move Lib/unittest/test/ to Lib/test/test_unittest/ --- Lib/{unittest/test => test/test_unittest}/__init__.py | 0 Lib/{unittest/test => test/test_unittest}/__main__.py | 0 Lib/{unittest/test => test/test_unittest}/_test_warnings.py | 0 Lib/{unittest/test => test/test_unittest}/dummy.py | 0 Lib/{unittest/test => test/test_unittest}/support.py | 0 Lib/{unittest/test => test/test_unittest}/test_assertions.py | 0 Lib/{unittest/test => test/test_unittest}/test_async_case.py | 0 Lib/{unittest/test => test/test_unittest}/test_break.py | 0 Lib/{unittest/test => test/test_unittest}/test_case.py | 0 Lib/{unittest/test => test/test_unittest}/test_discovery.py | 0 .../test => test/test_unittest}/test_functiontestcase.py | 0 Lib/{unittest/test => test/test_unittest}/test_loader.py | 0 Lib/{unittest/test => test/test_unittest}/test_program.py | 0 Lib/{unittest/test => test/test_unittest}/test_result.py | 0 Lib/{unittest/test => test/test_unittest}/test_runner.py | 0 Lib/{unittest/test => test/test_unittest}/test_setups.py | 0 Lib/{unittest/test => test/test_unittest}/test_skipping.py | 0 Lib/{unittest/test => test/test_unittest}/test_suite.py | 0 Lib/{unittest/test => test/test_unittest}/testmock/__init__.py | 0 Lib/{unittest/test => test/test_unittest}/testmock/__main__.py | 0 Lib/{unittest/test => test/test_unittest}/testmock/support.py | 0 Lib/{unittest/test => test/test_unittest}/testmock/testasync.py | 0 .../test => test/test_unittest}/testmock/testcallable.py | 0 Lib/{unittest/test => test/test_unittest}/testmock/testhelpers.py | 0 .../test => test/test_unittest}/testmock/testmagicmethods.py | 0 Lib/{unittest/test => test/test_unittest}/testmock/testmock.py | 0 Lib/{unittest/test => test/test_unittest}/testmock/testpatch.py | 0 .../test => test/test_unittest}/testmock/testsealable.py | 0 .../test => test/test_unittest}/testmock/testsentinel.py | 0 Lib/{unittest/test => test/test_unittest}/testmock/testwith.py | 0 30 files changed, 0 insertions(+), 0 deletions(-) rename Lib/{unittest/test => test/test_unittest}/__init__.py (100%) rename Lib/{unittest/test => test/test_unittest}/__main__.py (100%) rename Lib/{unittest/test => test/test_unittest}/_test_warnings.py (100%) rename Lib/{unittest/test => test/test_unittest}/dummy.py (100%) rename Lib/{unittest/test => test/test_unittest}/support.py (100%) rename Lib/{unittest/test => test/test_unittest}/test_assertions.py (100%) rename Lib/{unittest/test => test/test_unittest}/test_async_case.py (100%) rename Lib/{unittest/test => test/test_unittest}/test_break.py (100%) rename Lib/{unittest/test => test/test_unittest}/test_case.py (100%) rename Lib/{unittest/test => test/test_unittest}/test_discovery.py (100%) rename Lib/{unittest/test => test/test_unittest}/test_functiontestcase.py (100%) rename Lib/{unittest/test => test/test_unittest}/test_loader.py (100%) rename Lib/{unittest/test => test/test_unittest}/test_program.py (100%) rename Lib/{unittest/test => test/test_unittest}/test_result.py (100%) rename Lib/{unittest/test => test/test_unittest}/test_runner.py (100%) rename Lib/{unittest/test => test/test_unittest}/test_setups.py (100%) rename Lib/{unittest/test => test/test_unittest}/test_skipping.py (100%) rename Lib/{unittest/test => test/test_unittest}/test_suite.py (100%) rename Lib/{unittest/test => test/test_unittest}/testmock/__init__.py (100%) rename Lib/{unittest/test => test/test_unittest}/testmock/__main__.py (100%) rename Lib/{unittest/test => test/test_unittest}/testmock/support.py (100%) rename Lib/{unittest/test => test/test_unittest}/testmock/testasync.py (100%) rename Lib/{unittest/test => test/test_unittest}/testmock/testcallable.py (100%) rename Lib/{unittest/test => test/test_unittest}/testmock/testhelpers.py (100%) rename Lib/{unittest/test => test/test_unittest}/testmock/testmagicmethods.py (100%) rename Lib/{unittest/test => test/test_unittest}/testmock/testmock.py (100%) rename Lib/{unittest/test => test/test_unittest}/testmock/testpatch.py (100%) rename Lib/{unittest/test => test/test_unittest}/testmock/testsealable.py (100%) rename Lib/{unittest/test => test/test_unittest}/testmock/testsentinel.py (100%) rename Lib/{unittest/test => test/test_unittest}/testmock/testwith.py (100%) diff --git a/Lib/unittest/test/__init__.py b/Lib/test/test_unittest/__init__.py similarity index 100% rename from Lib/unittest/test/__init__.py rename to Lib/test/test_unittest/__init__.py diff --git a/Lib/unittest/test/__main__.py b/Lib/test/test_unittest/__main__.py similarity index 100% rename from Lib/unittest/test/__main__.py rename to Lib/test/test_unittest/__main__.py diff --git a/Lib/unittest/test/_test_warnings.py b/Lib/test/test_unittest/_test_warnings.py similarity index 100% rename from Lib/unittest/test/_test_warnings.py rename to Lib/test/test_unittest/_test_warnings.py diff --git a/Lib/unittest/test/dummy.py b/Lib/test/test_unittest/dummy.py similarity index 100% rename from Lib/unittest/test/dummy.py rename to Lib/test/test_unittest/dummy.py diff --git a/Lib/unittest/test/support.py b/Lib/test/test_unittest/support.py similarity index 100% rename from Lib/unittest/test/support.py rename to Lib/test/test_unittest/support.py diff --git a/Lib/unittest/test/test_assertions.py b/Lib/test/test_unittest/test_assertions.py similarity index 100% rename from Lib/unittest/test/test_assertions.py rename to Lib/test/test_unittest/test_assertions.py diff --git a/Lib/unittest/test/test_async_case.py b/Lib/test/test_unittest/test_async_case.py similarity index 100% rename from Lib/unittest/test/test_async_case.py rename to Lib/test/test_unittest/test_async_case.py diff --git a/Lib/unittest/test/test_break.py b/Lib/test/test_unittest/test_break.py similarity index 100% rename from Lib/unittest/test/test_break.py rename to Lib/test/test_unittest/test_break.py diff --git a/Lib/unittest/test/test_case.py b/Lib/test/test_unittest/test_case.py similarity index 100% rename from Lib/unittest/test/test_case.py rename to Lib/test/test_unittest/test_case.py diff --git a/Lib/unittest/test/test_discovery.py b/Lib/test/test_unittest/test_discovery.py similarity index 100% rename from Lib/unittest/test/test_discovery.py rename to Lib/test/test_unittest/test_discovery.py diff --git a/Lib/unittest/test/test_functiontestcase.py b/Lib/test/test_unittest/test_functiontestcase.py similarity index 100% rename from Lib/unittest/test/test_functiontestcase.py rename to Lib/test/test_unittest/test_functiontestcase.py diff --git a/Lib/unittest/test/test_loader.py b/Lib/test/test_unittest/test_loader.py similarity index 100% rename from Lib/unittest/test/test_loader.py rename to Lib/test/test_unittest/test_loader.py diff --git a/Lib/unittest/test/test_program.py b/Lib/test/test_unittest/test_program.py similarity index 100% rename from Lib/unittest/test/test_program.py rename to Lib/test/test_unittest/test_program.py diff --git a/Lib/unittest/test/test_result.py b/Lib/test/test_unittest/test_result.py similarity index 100% rename from Lib/unittest/test/test_result.py rename to Lib/test/test_unittest/test_result.py diff --git a/Lib/unittest/test/test_runner.py b/Lib/test/test_unittest/test_runner.py similarity index 100% rename from Lib/unittest/test/test_runner.py rename to Lib/test/test_unittest/test_runner.py diff --git a/Lib/unittest/test/test_setups.py b/Lib/test/test_unittest/test_setups.py similarity index 100% rename from Lib/unittest/test/test_setups.py rename to Lib/test/test_unittest/test_setups.py diff --git a/Lib/unittest/test/test_skipping.py b/Lib/test/test_unittest/test_skipping.py similarity index 100% rename from Lib/unittest/test/test_skipping.py rename to Lib/test/test_unittest/test_skipping.py diff --git a/Lib/unittest/test/test_suite.py b/Lib/test/test_unittest/test_suite.py similarity index 100% rename from Lib/unittest/test/test_suite.py rename to Lib/test/test_unittest/test_suite.py diff --git a/Lib/unittest/test/testmock/__init__.py b/Lib/test/test_unittest/testmock/__init__.py similarity index 100% rename from Lib/unittest/test/testmock/__init__.py rename to Lib/test/test_unittest/testmock/__init__.py diff --git a/Lib/unittest/test/testmock/__main__.py b/Lib/test/test_unittest/testmock/__main__.py similarity index 100% rename from Lib/unittest/test/testmock/__main__.py rename to Lib/test/test_unittest/testmock/__main__.py diff --git a/Lib/unittest/test/testmock/support.py b/Lib/test/test_unittest/testmock/support.py similarity index 100% rename from Lib/unittest/test/testmock/support.py rename to Lib/test/test_unittest/testmock/support.py diff --git a/Lib/unittest/test/testmock/testasync.py b/Lib/test/test_unittest/testmock/testasync.py similarity index 100% rename from Lib/unittest/test/testmock/testasync.py rename to Lib/test/test_unittest/testmock/testasync.py diff --git a/Lib/unittest/test/testmock/testcallable.py b/Lib/test/test_unittest/testmock/testcallable.py similarity index 100% rename from Lib/unittest/test/testmock/testcallable.py rename to Lib/test/test_unittest/testmock/testcallable.py diff --git a/Lib/unittest/test/testmock/testhelpers.py b/Lib/test/test_unittest/testmock/testhelpers.py similarity index 100% rename from Lib/unittest/test/testmock/testhelpers.py rename to Lib/test/test_unittest/testmock/testhelpers.py diff --git a/Lib/unittest/test/testmock/testmagicmethods.py b/Lib/test/test_unittest/testmock/testmagicmethods.py similarity index 100% rename from Lib/unittest/test/testmock/testmagicmethods.py rename to Lib/test/test_unittest/testmock/testmagicmethods.py diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/test/test_unittest/testmock/testmock.py similarity index 100% rename from Lib/unittest/test/testmock/testmock.py rename to Lib/test/test_unittest/testmock/testmock.py diff --git a/Lib/unittest/test/testmock/testpatch.py b/Lib/test/test_unittest/testmock/testpatch.py similarity index 100% rename from Lib/unittest/test/testmock/testpatch.py rename to Lib/test/test_unittest/testmock/testpatch.py diff --git a/Lib/unittest/test/testmock/testsealable.py b/Lib/test/test_unittest/testmock/testsealable.py similarity index 100% rename from Lib/unittest/test/testmock/testsealable.py rename to Lib/test/test_unittest/testmock/testsealable.py diff --git a/Lib/unittest/test/testmock/testsentinel.py b/Lib/test/test_unittest/testmock/testsentinel.py similarity index 100% rename from Lib/unittest/test/testmock/testsentinel.py rename to Lib/test/test_unittest/testmock/testsentinel.py diff --git a/Lib/unittest/test/testmock/testwith.py b/Lib/test/test_unittest/testmock/testwith.py similarity index 100% rename from Lib/unittest/test/testmock/testwith.py rename to Lib/test/test_unittest/testmock/testwith.py From 9320efc4b4d497527e09531cf8210d476b6bac40 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 20 Jun 2022 23:14:24 +0200 Subject: [PATCH 3/6] * Replace unittest.test with test.test_unittest --- Lib/test/test_unittest/__init__.py | 4 ++-- Lib/test/test_unittest/__main__.py | 2 +- Lib/test/test_unittest/test_case.py | 2 +- Lib/test/test_unittest/test_discovery.py | 6 ++--- .../test_unittest/test_functiontestcase.py | 2 +- Lib/test/test_unittest/test_loader.py | 6 ++--- Lib/test/test_unittest/test_program.py | 16 +++++++------- Lib/test/test_unittest/test_runner.py | 2 +- Lib/test/test_unittest/test_skipping.py | 2 +- Lib/test/test_unittest/test_suite.py | 2 +- Lib/test/test_unittest/testmock/__init__.py | 2 +- Lib/test/test_unittest/testmock/__main__.py | 2 +- .../test_unittest/testmock/testcallable.py | 2 +- Lib/test/test_unittest/testmock/testmock.py | 2 +- Lib/test/test_unittest/testmock/testpatch.py | 22 +++++++++---------- Lib/test/test_unittest/testmock/testwith.py | 2 +- 16 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Lib/test/test_unittest/__init__.py b/Lib/test/test_unittest/__init__.py index 143f4ab5a3d878..c2467f01772b01 100644 --- a/Lib/test/test_unittest/__init__.py +++ b/Lib/test/test_unittest/__init__.py @@ -10,14 +10,14 @@ def suite(): suite = unittest.TestSuite() for fn in os.listdir(here): if fn.startswith("test") and fn.endswith(".py"): - modname = "unittest.test." + fn[:-3] + modname = "test.test_unittest." + fn[:-3] try: __import__(modname) except unittest.SkipTest: continue module = sys.modules[modname] suite.addTest(loader.loadTestsFromModule(module)) - suite.addTest(loader.loadTestsFromName('unittest.test.testmock')) + suite.addTest(loader.loadTestsFromName('test.test_unittest.testmock')) return suite diff --git a/Lib/test/test_unittest/__main__.py b/Lib/test/test_unittest/__main__.py index 44d0591e8473af..b49656f763c0b6 100644 --- a/Lib/test/test_unittest/__main__.py +++ b/Lib/test/test_unittest/__main__.py @@ -6,7 +6,7 @@ def load_tests(loader, standard_tests, pattern): # top level directory cached on loader instance this_dir = os.path.dirname(__file__) pattern = pattern or "test_*.py" - # We are inside unittest.test, so the top-level is two notches up + # We are inside test.test_unittest, so the top-level is two notches up top_level_dir = os.path.dirname(os.path.dirname(this_dir)) package_tests = loader.discover(start_dir=this_dir, pattern=pattern, top_level_dir=top_level_dir) diff --git a/Lib/test/test_unittest/test_case.py b/Lib/test/test_unittest/test_case.py index 374a255255566f..e000fe4f072407 100644 --- a/Lib/test/test_unittest/test_case.py +++ b/Lib/test/test_unittest/test_case.py @@ -15,7 +15,7 @@ import unittest -from unittest.test.support import ( +from test.test_unittest.support import ( TestEquality, TestHashing, LoggingResult, LegacyLoggingResult, ResultWithNoStartTestRunStopTestRun ) diff --git a/Lib/test/test_unittest/test_discovery.py b/Lib/test/test_unittest/test_discovery.py index 3b58786ec16a10..946fa1258ea25e 100644 --- a/Lib/test/test_unittest/test_discovery.py +++ b/Lib/test/test_unittest/test_discovery.py @@ -10,7 +10,7 @@ import unittest import unittest.mock -import unittest.test +import test.test_unittest class TestableTestProgram(unittest.TestProgram): @@ -789,7 +789,7 @@ def test_discovery_from_dotted_path(self): loader = unittest.TestLoader() tests = [self] - expectedPath = os.path.abspath(os.path.dirname(unittest.test.__file__)) + expectedPath = os.path.abspath(os.path.dirname(test.test_unittest.__file__)) self.wasRun = False def _find_tests(start_dir, pattern): @@ -797,7 +797,7 @@ def _find_tests(start_dir, pattern): self.assertEqual(start_dir, expectedPath) return tests loader._find_tests = _find_tests - suite = loader.discover('unittest.test') + suite = loader.discover('test.test_unittest') self.assertTrue(self.wasRun) self.assertEqual(suite._tests, tests) diff --git a/Lib/test/test_unittest/test_functiontestcase.py b/Lib/test/test_unittest/test_functiontestcase.py index 4971729880d6d8..2ebed9564ad9cd 100644 --- a/Lib/test/test_unittest/test_functiontestcase.py +++ b/Lib/test/test_unittest/test_functiontestcase.py @@ -1,6 +1,6 @@ import unittest -from unittest.test.support import LoggingResult +from test.test_unittest.support import LoggingResult class Test_FunctionTestCase(unittest.TestCase): diff --git a/Lib/test/test_unittest/test_loader.py b/Lib/test/test_unittest/test_loader.py index de2268cda90688..c06ebb658d2874 100644 --- a/Lib/test/test_unittest/test_loader.py +++ b/Lib/test/test_unittest/test_loader.py @@ -716,7 +716,7 @@ def test_loadTestsFromName__module_not_loaded(self): # We're going to try to load this module as a side-effect, so it # better not be loaded before we try. # - module_name = 'unittest.test.dummy' + module_name = 'test.test_unittest.dummy' sys.modules.pop(module_name, None) loader = unittest.TestLoader() @@ -844,7 +844,7 @@ def test_loadTestsFromNames__unknown_attr_name(self): loader = unittest.TestLoader() suite = loader.loadTestsFromNames( - ['unittest.loader.sdasfasfasdf', 'unittest.test.dummy']) + ['unittest.loader.sdasfasfasdf', 'test.test_unittest.dummy']) error, test = self.check_deferred_error(loader, list(suite)[0]) expected = "module 'unittest.loader' has no attribute 'sdasfasfasdf'" self.assertIn( @@ -1141,7 +1141,7 @@ def test_loadTestsFromNames__module_not_loaded(self): # We're going to try to load this module as a side-effect, so it # better not be loaded before we try. # - module_name = 'unittest.test.dummy' + module_name = 'test.test_unittest.dummy' sys.modules.pop(module_name, None) loader = unittest.TestLoader() diff --git a/Lib/test/test_unittest/test_program.py b/Lib/test/test_unittest/test_program.py index 26a8550af8fdd2..169fc4ed9401f9 100644 --- a/Lib/test/test_unittest/test_program.py +++ b/Lib/test/test_unittest/test_program.py @@ -5,8 +5,8 @@ import subprocess from test import support import unittest -import unittest.test -from unittest.test.test_result import BufferedWriter +import test.test_unittest +from test.test_unittest.test_result import BufferedWriter class Test_TestProgram(unittest.TestCase): @@ -15,7 +15,7 @@ def test_discovery_from_dotted_path(self): loader = unittest.TestLoader() tests = [self] - expectedPath = os.path.abspath(os.path.dirname(unittest.test.__file__)) + expectedPath = os.path.abspath(os.path.dirname(test.test_unittest.__file__)) self.wasRun = False def _find_tests(start_dir, pattern): @@ -23,7 +23,7 @@ def _find_tests(start_dir, pattern): self.assertEqual(start_dir, expectedPath) return tests loader._find_tests = _find_tests - suite = loader.discover('unittest.test') + suite = loader.discover('test.test_unittest') self.assertTrue(self.wasRun) self.assertEqual(suite._tests, tests) @@ -93,10 +93,10 @@ def run(self, test): sys.argv = ['faketest'] runner = FakeRunner() program = unittest.TestProgram(testRunner=runner, exit=False, - defaultTest='unittest.test', + defaultTest='test.test_unittest', testLoader=self.FooBarLoader()) sys.argv = old_argv - self.assertEqual(('unittest.test',), program.testNames) + self.assertEqual(('test.test_unittest',), program.testNames) def test_defaultTest_with_iterable(self): class FakeRunner(object): @@ -109,10 +109,10 @@ def run(self, test): runner = FakeRunner() program = unittest.TestProgram( testRunner=runner, exit=False, - defaultTest=['unittest.test', 'unittest.test2'], + defaultTest=['test.test_unittest', 'test.test_unittest2'], testLoader=self.FooBarLoader()) sys.argv = old_argv - self.assertEqual(['unittest.test', 'unittest.test2'], + self.assertEqual(['test.test_unittest', 'test.test_unittest2'], program.testNames) def test_NonExit(self): diff --git a/Lib/test/test_unittest/test_runner.py b/Lib/test/test_unittest/test_runner.py index d3488b40e82bde..9e3a0a9ca08d65 100644 --- a/Lib/test/test_unittest/test_runner.py +++ b/Lib/test/test_unittest/test_runner.py @@ -8,7 +8,7 @@ import unittest from unittest.case import _Outcome -from unittest.test.support import (LoggingResult, +from test.test_unittest.support import (LoggingResult, ResultWithNoStartTestRunStopTestRun) diff --git a/Lib/test/test_unittest/test_skipping.py b/Lib/test/test_unittest/test_skipping.py index 64ceeae37ef0a7..f146dcac18ecc0 100644 --- a/Lib/test/test_unittest/test_skipping.py +++ b/Lib/test/test_unittest/test_skipping.py @@ -1,6 +1,6 @@ import unittest -from unittest.test.support import LoggingResult +from test.test_unittest.support import LoggingResult class Test_TestSkipping(unittest.TestCase): diff --git a/Lib/test/test_unittest/test_suite.py b/Lib/test/test_unittest/test_suite.py index 0551a16996723e..ca52ee9d9c011c 100644 --- a/Lib/test/test_unittest/test_suite.py +++ b/Lib/test/test_unittest/test_suite.py @@ -3,7 +3,7 @@ import gc import sys import weakref -from unittest.test.support import LoggingResult, TestEquality +from test.test_unittest.support import LoggingResult, TestEquality ### Support code for Test_TestSuite diff --git a/Lib/test/test_unittest/testmock/__init__.py b/Lib/test/test_unittest/testmock/__init__.py index 87d7ae994d5cd3..6ee60b23765e07 100644 --- a/Lib/test/test_unittest/testmock/__init__.py +++ b/Lib/test/test_unittest/testmock/__init__.py @@ -10,7 +10,7 @@ def load_tests(*args): suite = unittest.TestSuite() for fn in os.listdir(here): if fn.startswith("test") and fn.endswith(".py"): - modname = "unittest.test.testmock." + fn[:-3] + modname = "test.test_unittest.testmock." + fn[:-3] __import__(modname) module = sys.modules[modname] suite.addTest(loader.loadTestsFromModule(module)) diff --git a/Lib/test/test_unittest/testmock/__main__.py b/Lib/test/test_unittest/testmock/__main__.py index 45c633a4ee48b5..1e3068b0ddf391 100644 --- a/Lib/test/test_unittest/testmock/__main__.py +++ b/Lib/test/test_unittest/testmock/__main__.py @@ -6,7 +6,7 @@ def load_tests(loader, standard_tests, pattern): # top level directory cached on loader instance this_dir = os.path.dirname(__file__) pattern = pattern or "test*.py" - # We are inside unittest.test.testmock, so the top-level is three notches up + # We are inside test.test_unittest.testmock, so the top-level is three notches up top_level_dir = os.path.dirname(os.path.dirname(os.path.dirname(this_dir))) package_tests = loader.discover(start_dir=this_dir, pattern=pattern, top_level_dir=top_level_dir) diff --git a/Lib/test/test_unittest/testmock/testcallable.py b/Lib/test/test_unittest/testmock/testcallable.py index 5eadc007049400..ca88511f63959d 100644 --- a/Lib/test/test_unittest/testmock/testcallable.py +++ b/Lib/test/test_unittest/testmock/testcallable.py @@ -3,7 +3,7 @@ # http://www.voidspace.org.uk/python/mock/ import unittest -from unittest.test.testmock.support import is_instance, X, SomeClass +from test.test_unittest.testmock.support import is_instance, X, SomeClass from unittest.mock import ( Mock, MagicMock, NonCallableMagicMock, diff --git a/Lib/test/test_unittest/testmock/testmock.py b/Lib/test/test_unittest/testmock/testmock.py index c99098dc4ea86a..8a92490137f9a7 100644 --- a/Lib/test/test_unittest/testmock/testmock.py +++ b/Lib/test/test_unittest/testmock/testmock.py @@ -5,7 +5,7 @@ from test.support import ALWAYS_EQ import unittest -from unittest.test.testmock.support import is_instance +from test.test_unittest.testmock.support import is_instance from unittest import mock from unittest.mock import ( call, DEFAULT, patch, sentinel, diff --git a/Lib/test/test_unittest/testmock/testpatch.py b/Lib/test/test_unittest/testmock/testpatch.py index 8ab63a1317d3df..93ec0ca4bef524 100644 --- a/Lib/test/test_unittest/testmock/testpatch.py +++ b/Lib/test/test_unittest/testmock/testpatch.py @@ -7,8 +7,8 @@ from collections import OrderedDict import unittest -from unittest.test.testmock import support -from unittest.test.testmock.support import SomeClass, is_instance +from test.test_unittest.testmock import support +from test.test_unittest.testmock.support import SomeClass, is_instance from test.test_importlib.util import uncache from unittest.mock import ( @@ -669,7 +669,7 @@ def test_patch_dict_decorator_resolution(self): # the new dictionary during function call original = support.target.copy() - @patch.dict('unittest.test.testmock.support.target', {'bar': 'BAR'}) + @patch.dict('test.test_unittest.testmock.support.target', {'bar': 'BAR'}) def test(): self.assertEqual(support.target, {'foo': 'BAZ', 'bar': 'BAR'}) @@ -1614,7 +1614,7 @@ def test_patch_with_spec_mock_repr(self): def test_patch_nested_autospec_repr(self): - with patch('unittest.test.testmock.support', autospec=True) as m: + with patch('test.test_unittest.testmock.support', autospec=True) as m: self.assertIn(" name='support.SomeClass.wibble()'", repr(m.SomeClass.wibble())) self.assertIn(" name='support.SomeClass().wibble()'", @@ -1882,7 +1882,7 @@ def foo(x=0): with patch.object(foo, '__module__', "testpatch2"): self.assertEqual(foo.__module__, "testpatch2") - self.assertEqual(foo.__module__, 'unittest.test.testmock.testpatch') + self.assertEqual(foo.__module__, 'test.test_unittest.testmock.testpatch') with patch.object(foo, '__annotations__', dict([('s', 1, )])): self.assertEqual(foo.__annotations__, dict([('s', 1, )])) @@ -1917,16 +1917,16 @@ def test_dotted_but_module_not_loaded(self): # This exercises the AttributeError branch of _dot_lookup. # make sure it's there - import unittest.test.testmock.support + import test.test_unittest.testmock.support # now make sure it's not: with patch.dict('sys.modules'): - del sys.modules['unittest.test.testmock.support'] - del sys.modules['unittest.test.testmock'] - del sys.modules['unittest.test'] + del sys.modules['test.test_unittest.testmock.support'] + del sys.modules['test.test_unittest.testmock'] + del sys.modules['test.test_unittest'] del sys.modules['unittest'] # now make sure we can patch based on a dotted path: - @patch('unittest.test.testmock.support.X') + @patch('test.test_unittest.testmock.support.X') def test(mock): pass test() @@ -1943,7 +1943,7 @@ class Foo: def test_cant_set_kwargs_when_passing_a_mock(self): - @patch('unittest.test.testmock.support.X', new=object(), x=1) + @patch('test.test_unittest.testmock.support.X', new=object(), x=1) def test(): pass with self.assertRaises(TypeError): test() diff --git a/Lib/test/test_unittest/testmock/testwith.py b/Lib/test/test_unittest/testmock/testwith.py index c74d49a63c8928..8dc8eb1137691f 100644 --- a/Lib/test/test_unittest/testmock/testwith.py +++ b/Lib/test/test_unittest/testmock/testwith.py @@ -1,7 +1,7 @@ import unittest from warnings import catch_warnings -from unittest.test.testmock.support import is_instance +from test.test_unittest.testmock.support import is_instance from unittest.mock import MagicMock, Mock, patch, sentinel, mock_open, call From 917e6f58e51e7e431e668e54b8fd474a2b669e0a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 20 Jun 2022 23:15:36 +0200 Subject: [PATCH 4/6] * Remove unittest.load_tests() --- Lib/unittest/__init__.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Lib/unittest/__init__.py b/Lib/unittest/__init__.py index 005d23f6d00ecb..b8de8c95d61584 100644 --- a/Lib/unittest/__init__.py +++ b/Lib/unittest/__init__.py @@ -73,16 +73,6 @@ def testMultiply(self): _TextTestResult = TextTestResult -# There are no tests here, so don't try to run anything discovered from -# introspecting the symbols (e.g. FunctionTestCase). Instead, all our -# tests come from within unittest.test. -def load_tests(loader, tests, pattern): - import os.path - # top level directory cached on loader instance - this_dir = os.path.dirname(__file__) - return loader.discover(start_dir=this_dir, pattern=pattern) - - # Lazy import of IsolatedAsyncioTestCase from .async_case # It imports asyncio, which is relatively heavy, but most tests # do not need it. From 34a8a1b6ed71a43c1a4670bf3141f4b88dae4f41 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 20 Jun 2022 23:19:24 +0200 Subject: [PATCH 5/6] * Rewrite __init__.py and __main__.py --- Lib/test/test_unittest/__init__.py | 27 ++++----------------------- Lib/test/test_unittest/__main__.py | 18 ++---------------- 2 files changed, 6 insertions(+), 39 deletions(-) diff --git a/Lib/test/test_unittest/__init__.py b/Lib/test/test_unittest/__init__.py index c2467f01772b01..bc502ef32d2916 100644 --- a/Lib/test/test_unittest/__init__.py +++ b/Lib/test/test_unittest/__init__.py @@ -1,25 +1,6 @@ -import os -import sys -import unittest +import os.path +from test.support import load_package_tests -here = os.path.dirname(__file__) -loader = unittest.defaultTestLoader - -def suite(): - suite = unittest.TestSuite() - for fn in os.listdir(here): - if fn.startswith("test") and fn.endswith(".py"): - modname = "test.test_unittest." + fn[:-3] - try: - __import__(modname) - except unittest.SkipTest: - continue - module = sys.modules[modname] - suite.addTest(loader.loadTestsFromModule(module)) - suite.addTest(loader.loadTestsFromName('test.test_unittest.testmock')) - return suite - - -if __name__ == "__main__": - unittest.main(defaultTest="suite") +def load_tests(*args): + return load_package_tests(os.path.dirname(__file__), *args) diff --git a/Lib/test/test_unittest/__main__.py b/Lib/test/test_unittest/__main__.py index b49656f763c0b6..40a23a297ec2b4 100644 --- a/Lib/test/test_unittest/__main__.py +++ b/Lib/test/test_unittest/__main__.py @@ -1,18 +1,4 @@ -import os +from . import load_tests import unittest - -def load_tests(loader, standard_tests, pattern): - # top level directory cached on loader instance - this_dir = os.path.dirname(__file__) - pattern = pattern or "test_*.py" - # We are inside test.test_unittest, so the top-level is two notches up - top_level_dir = os.path.dirname(os.path.dirname(this_dir)) - package_tests = loader.discover(start_dir=this_dir, pattern=pattern, - top_level_dir=top_level_dir) - standard_tests.addTests(package_tests) - return standard_tests - - -if __name__ == '__main__': - unittest.main() +unittest.main() From 3e8a7937a92f01835e0a97a0d8d989921c47d169 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 20 Jun 2022 23:24:44 +0200 Subject: [PATCH 6/6] * Update build system, CODEOWNERS, wasm_assets.py --- .github/CODEOWNERS | 2 +- Makefile.pre.in | 4 +-- PCbuild/lib.pyproj | 58 +++++++++++++++++++-------------------- Tools/wasm/wasm_assets.py | 1 - 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 8f9eefaeaa2e84..58023b63833eee 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -97,7 +97,7 @@ Lib/ast.py @isidentical # Mock /Lib/unittest/mock.py @cjw296 -/Lib/unittest/test/testmock/* @cjw296 +/Lib/test/test_unittest/testmock/* @cjw296 # SQLite 3 **/*sqlite* @berkerpeksag @erlend-aasland diff --git a/Makefile.pre.in b/Makefile.pre.in index eaaab5e0118f19..0bbb7360ea459f 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1989,12 +1989,12 @@ TESTSUBDIRS= ctypes/test \ test/test_tools \ test/test_warnings test/test_warnings/data \ test/test_zoneinfo test/test_zoneinfo/data \ + test/test_unittest test/test_unittest/testmock \ test/tracedmodules \ test/xmltestdata test/xmltestdata/c14n-20 \ test/ziptestdata \ tkinter/test tkinter/test/test_tkinter \ - tkinter/test/test_ttk \ - unittest/test unittest/test/testmock + tkinter/test/test_ttk TEST_MODULES=@TEST_MODULES@ libinstall: all $(srcdir)/Modules/xxmodule.c diff --git a/PCbuild/lib.pyproj b/PCbuild/lib.pyproj index 43c570f1dab37a..731bdb74b4470c 100644 --- a/PCbuild/lib.pyproj +++ b/PCbuild/lib.pyproj @@ -1492,33 +1492,33 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1805,6 +1805,8 @@ + + @@ -1814,8 +1816,6 @@ - - diff --git a/Tools/wasm/wasm_assets.py b/Tools/wasm/wasm_assets.py index b7e83517cae036..85c92e66cf787d 100755 --- a/Tools/wasm/wasm_assets.py +++ b/Tools/wasm/wasm_assets.py @@ -113,7 +113,6 @@ OMIT_SUBDIRS = ( "ctypes/test/", "tkinter/test/", - "unittest/test/", ) def get_builddir(args: argparse.Namespace) -> pathlib.Path: