[Python-Dev] Python equivalents in stdlib Was: Include datetime.py in stdlib or not? (original) (raw)

Alexander Belopolsky alexander.belopolsky at gmail.com
Thu Jul 8 21:24:37 CEST 2010


On Thu, Jul 8, 2010 at 10:59 AM, Nick Coghlan <ncoghlan at gmail.com> wrote: ..

I realised during the day that my suggested approach was more complicated than is actually necessary - once the existing tests have been moved to a separate module, that test module can itself be imported twice, once with the python version of the module to be tested and once with the C version. You can then do some hackery to distinguish the test classes without having to modify the test code itself (note, the below code should work in theory, but isn't actually tested):

============= pymoduletests = support.importfreshmodule('moduletester', fresh=['modulename'], blocked=['modulename']) cmoduletests = support.importfreshmodule('moduletester', fresh=['modulename', 'modulename']) testmodules = [pymoduletests, cmoduletests] suffixes = ["Py", "C"] for module, suffix in zip(testmodules, suffixes):  for obj in module.itervalues():  if isinstance(obj, unittest,TestCase):  obj.name += suffix  setattr(module, obj.name, obj) def testmain():  for module in testmodules:  module.testmain() =============

Yes, this is definitely an improvement over my current datetime patch [1]_, but it still requires a custom test_main() and does not make the test cases discoverable by alternative unittest runners. I think that can be fixed by injecting imported TestCase subclasses into the main test module globals. I'll try to implement that for datetime. Thanks, Nick - great idea!

.. [1] http://bugs.python.org/file17848/issue7989.diff



More information about the Python-Dev mailing list