[Python-checkins] cpython: Make test_datetime a better citizen (issue #22540)

antoine.pitrou python-checkins at python.org
Fri Oct 3 11:28:42 CEST 2014


https://hg.python.org/cpython/rev/6cfe929d1de5
changeset:   92767:6cfe929d1de5
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Fri Oct 03 11:25:30 2014 +0200
summary:
  Make test_datetime a better citizen (issue #22540)

files:
  Lib/test/datetimetester.py |   2 +-
  Lib/test/test_datetime.py  |  10 +++++-----
  2 files changed, 6 insertions(+), 6 deletions(-)


diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -3,6 +3,7 @@
 See http://www.zope.org/Members/fdrake/DateTimeWiki/TestCases
 """
 
+import decimal
 import sys
 import pickle
 import random
@@ -3808,7 +3809,6 @@
                 x.abc = 1
 
     def test_check_arg_types(self):
-        import decimal
         class Number:
             def __init__(self, value):
                 self.value = value
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -1,20 +1,20 @@
 import unittest
 import sys
+
 from test.support import import_fresh_module, run_unittest
 
 TESTS = 'test.datetimetester'
 
-# XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
-# XXX: but it does not, so we have to save and restore it ourselves.
-save_sys_modules = sys.modules.copy()
 try:
     pure_tests = import_fresh_module(TESTS, fresh=['datetime', '_strptime'],
                                      blocked=['_datetime'])
     fast_tests = import_fresh_module(TESTS, fresh=['datetime',
                                                    '_datetime', '_strptime'])
 finally:
-    sys.modules.clear()
-    sys.modules.update(save_sys_modules)
+    # XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
+    # XXX: but it does not, so we have to cleanup ourselves.
+    for modname in ['datetime', '_datetime', '_strptime']:
+        sys.modules.pop(modname, None)
 test_modules = [pure_tests, fast_tests]
 test_suffixes = ["_Pure", "_Fast"]
 # XXX(gb) First run all the _Pure tests, then all the _Fast tests.  You might

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list