question about an exciting gotcha for unittests (and elsewhere) ...
gagsl-py2 at yahoo.com.ar
Fri Apr 23 21:35:55 CEST 2010
En Fri, 23 Apr 2010 03:15:16 -0300, Cameron Simpson <cs at zip.com.au>
> On 23Apr2010 15:37, I wrote:
> | Experienced users will see at once what's happened: I've made a Node
> | myself in the test using the local class, and the Node class is thus
> | __main__.Node. However, my sql Backend class has independently imported
> | the "Node" and "Backend" classes from "cs.nodedb.node". So when _it_
> | calls serialise(), "Node" is "cs.nodedb.node.Node".
> A walk around the block and I'm thinking the olny sane way to do this is
> to use relative imports, to always get the sqla.py module from the same
> place as the node.py where the test lives, and likewise in sqla.py
> to relatively import node.py to get its matching file.
Another way is to split the test code and move it into its own module.
This way, the testing code will import the node module the same way the
real application would do.
More information about the Python-list