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

Nick Coghlan ncoghlan at gmail.com
Thu Jul 8 00:27:56 CEST 2010


On Thu, Jul 8, 2010 at 7:36 AM, Brett Cannon <brett at python.org> wrote:

Selecting one of two globally defined different subclasses will be ugly in parameterized tests. Didn't say it was a pretty solution. =)

 An in the other approach, the class definitions will have to be moved away from the module level and inside a scope where module variable is present. Yep, which is not a big deal.  Yes, it looks like some refactoring is unavoidable.

If you want to run the same module twice with different instances of an imported module (or any other parameterised globals), creative use of run_module() can provide module level scoping without completely restructuring your tests.

  1. Move the current tests aside into a new file that isn't automatically invoked by regrtest (e.g. _test_datetime_inner.py).
  2. In that code, remove any imports from datetime (instead, assume datetime will be injected into the module's namespace)*
  3. In test_datetime.py itself, use runpy.run_module() to import the renamed module twice, once with the Python version of datetime in init_globals and once with the C version.

*How the removals work: "import datetime" is dropped entirely "from datetime import x, y, x" becomes "x, y, z = datetime.x, datetime.y, datetime.z"

There would be additional things to do to make the attribution of the test results clearer in order to make this effective in practice though.

Cheers, Nick.

-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia



More information about the Python-Dev mailing list