On Thu, Jul 8, 2010 at 5:46 PM, Nick Coghlan <ncogh...@gmail.com> wrote: .. > So include something along the lines of "globals()[obj.__name__] = > obj" in the name hacking loop to make the test classes more > discoverable? Good idea. >
As often happens, a good idea turns quite ugly when facing real world realities. I've uploaded a new patch at http://bugs.python.org/issue7989 and here is what I had to do to make this work for datetime: ========== import unittest import sys; sys.modules['_pickle'] = None from test.support import import_fresh_module, run_unittest TESTS = 'test.datetimetester' pure_tests = import_fresh_module(TESTS, fresh=['datetime', '_strptime', 'time'], blocked=['_datetime']) fast_tests = import_fresh_module(TESTS, fresh=['datetime', '_datetime', '_strptime', 'time']) test_modules = [pure_tests, fast_tests] test_suffixes = ["_Pure", "_Fast"] globs = globals() for module, suffix in zip(test_modules, test_suffixes): for name, cls in module.__dict__.items(): if isinstance(cls, type) and issubclass(cls, unittest.TestCase): name += suffix cls.__name__ = name globs[name] = cls def setUp(self, module=module, setup=cls.setUp): self._save_sys_modules = sys.modules.copy() sys.modules[TESTS] = module sys.modules['datetime'] = module.datetime_module sys.modules['_strptime'] = module.datetime_module._strptime setup(self) def tearDown(self, teardown=cls.tearDown): teardown(self) sys.modules = self._save_sys_modules cls.setUp = setUp cls.tearDown = tearDown def test_main(): run_unittest(__name__) ========= and it still requires that '_pickle' is disabled to pass pickle tests. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com