[TIP] tox, 2to3 and py.test

holger krekel holger at merlinux.eu
Tue Apr 3 06:49:58 PDT 2012


On Tue, Apr 03, 2012 at 16:34 +0300, Marius Gedminas wrote:
> On Tue, Apr 03, 2012 at 08:57:38AM +0000, Florian Bauer wrote:
> > > From: Eduardo Schettino [mailto:schettino72 at gmail.com] 
> > > On Mon, Apr 2, 2012 at 4:11 PM, Florian Bauer
> > > <Florian.Bauer at diasemi.com> wrote:
> > >  
> > >> The py.test documentation recommends that test/ should not be a
> > >> package, and I understand why.
> > >  
> > > I dont really understand why... and I could not find any
> > > reference in the docs on why this is recommended. Can someone
> > > please explain it?
> > 
> > Good that you ask, I think this point is a bit subtle.
> > The reason why you couldn't find anything in the docs is because I
> > gave the wrong reference, it is actually in the tox docs at the bottom
> > of the page here: http://tox.testrun.org/latest/example/pytest.html 
> > 
> > My project in its current form is a good example of the pitfalls of having a test package
> > 
> > Say this is my source code layout:
> > 
> >  mypackage/__init__.py
> >  mypackage/spam.py
> >  mypackage/test/__init__.py
> >  mypackage/test/test_spam.py
> > 
> > test_spam.py starts with
> > from mypackage.spam import eggs
> > 
> > if I now run py.test from my source directory, it would walk the file
> > system and find the file mypackage/test/test_spam.py Then it
> > constructs the fully qualified name of this file, which is
> > mypackage.test.test_spam , as it is part of a package, and imports it.
> > Likewise, mypackage.spam gets imported as well.  As long as I call
> > py.test from the source directory, I know that I imported the files
> > mypackage/spam.py and mypackage/test/test_spam.py
> > 
> > The fun begins in conjunction with tox and similar tools. Tox is
> > supposed to run code installed in a private a virtualenv, say
> > .tox/py26/lib/site-packages/mypackage or
> > .tox/py32/lib/site-packages/mypackage Which, in the given scenario it
> > won't do, because mypackage/test/test_spam comes earlier on the module
> > search path.
> 
> Why can't tox use setup.py develop so there's only one copy of the
> source files?  Is that incompatible with 2to3?

i guess its indeed incompatible but in any case, tox is used and meant as a
check that your packaged application works.  setup.py develop will also
pick up non-packaged files, wont it?

Holger


> Why is . in the python path anyway?
> 
> > I showed a tox.ini in my first e-mail that works around the issue, but
> > it took some time to figure out, why python3 was importing modules
> > containing python 2 syntax ;)
> 
> Marius Gedminas
> -- 
> Q: Is the Zombie Apocalypse a likely occurrence?
> A: It happens every morning when people drag their ass out of bed to go to
>    work. We seem to survive it.
>         -- http://whatever.scalzi.com/2009/04/05



> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python




More information about the testing-in-python mailing list