[Python-Dev] test___all__ polluting sys.modules? (original) (raw)

Eli Bendersky eliben at gmail.com
Sun Dec 30 15:17:01 CET 2012


On Sun, Dec 30, 2012 at 6:06 AM, Eli Bendersky <eliben at gmail.com> wrote:

On Sun, Dec 30, 2012 at 5:54 AM, Stefan Krah <stefan at bytereef.org> wrote: Eli Bendersky <eliben at gmail.com> wrote: > Yes, this is the solution currently used in testxmletree. However, once > pickling tests are added things stop working. Pickle uses import to import > the module a class belongs to, bypassing all such trickery. So if test_all_ > got elementtree into sys.modules, pickle's import finds it even if all the > tests in testxmletree manage to ignore it for the Python version because they > use importfreshmodule. I ran into the same problem for testdecimal. The only thing that appears to work is to set sys.modules['decimal'] explicitly before calling dumps()/loads(). See: PythonAPItests.testpickle() ContextAPItests.testpickle()

testdecimal ruthlessly switches sys.modules['decimal'] many times. At the end of all tests there is a sanity check that asserts that the number of changes were in fact balanced. Thank you, I'll try this. I'm also experimenting with other approaches. By the way, from clean default checkout: $ ./python -mtest test_all testint_ [1/2] test_all_ [2/2] testint test testint failed -- Traceback (most recent call last): File "/home/eliben/python-src/default/Lib/test/testint.py", line 236, in testkeywordargs self.assertRaises(TypeError, int, base=10) AssertionError: TypeError not raised by int 1 test OK. 1 test failed: testint Should this really fail? [I haven't investigated the root cause yet]

This is a false alarm, sorry. Please ignore this report (I had some stale build artifacts).

Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20121230/ce212e6a/attachment.html>



More information about the Python-Dev mailing list