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

Alexander Belopolsky alexander.belopolsky at gmail.com
Thu Jul 8 00:41:21 CEST 2010


On Wed, Jul 7, 2010 at 6:27 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
..
> 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.
>

This is what the current patch at

http://bugs.python.org/file17848/issue7989.diff

does, but at expense of not exposing testcases to unittest correctly.

> 1. Move the current tests aside into a new file that isn't
> automatically invoked by regrtest (e.g. _test_datetime_inner.py).

Yes, I already have datetimetester.py.

> 2. In that code, remove any imports from datetime (instead, assume
> datetime will be injected into the module's namespace)*

Hmm.  That will make datetimetester not importable.

> 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"
>
I'll try that.


> 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.

Thanks.  I would really like to make it work first and improve later.
I hope this will do the trick.


More information about the Python-Dev mailing list