[TIP] tox + py.test: test installed sdist

Alexander Steinert sputnik at termo.net
Thu Jul 7 00:35:04 PDT 2011


holger krekel, Wed 2011-07-06 17:11 CEST:
> > > Most people have their tests and package in subdirs.
> > > If you put test.py into a subdir, does it work?
> > 
> > No. I changed my example to be less minimal and more realistic (see
> > below).The result is the same. (Abs. path to) . is first in sys.path and
> > ./.tox/py26/lib/python2.6/site-packages is last.
> 
> This results from your package/tests/__init__.py file which will
> lead py.test to add the parent dir of package to sys.path
> before importing it.  See the "Note" in this section:
> 
>     http://doc.pytest.org/en/latest/goodpractises.html?highlight=good%20practises#choosing-a-test-layout-import-rules
> 
> If you remove package/tests/__init__.py then your test will pass because
> only 'package/tests' is added to sys.path in order to import test_module.

YMMD! Much too long ago that I read that part of py.test's doc.

> > IMHO, tox should take care that, during tests, modules are imported from
> > the installed sdist. Imagine your setup.py is flaky, say you package
> > no/wrong data files. You would never see that when you run tox.

> I am not sure how tox could check that modules are imported from
> the installed sdist.  I agree, however, that it's too easy to
> test against the inlined package instead of the installed one :/

If I find time, I'll formulate and suggest a note for tox's doc.

Regards
Stony




More information about the testing-in-python mailing list