[py-dev] Problems with test discovery (ImportError)

holger krekel holger at merlinux.eu
Thu May 20 12:49:31 CEST 2010


Hi Hans,

On Thu, May 20, 2010 at 12:43 +0200, Hans Meine wrote:
> Hi,
> 
> I had successfully toyed with py.test in the past, and just wanted to use it 
> again, instead of nosetests.  However, py.test fails with
> 
> E           ImportError: No module named something.test_foo
> 
> This seems to be caused by a package subdirectory called 'io'.  Here's how to 
> reproduce this (not necessarily minimal yet):
> 
> mkdir -p test_ImportError/io/something
> touch test_ImportError/io/something/test_foo.py
> touch test_ImportError/io/something/__init__.py
> touch test_ImportError/io/__init__.py
> py.test test_ImportError/io/something
> 
> Obviously, this is a bug that should be fixed, but I would already happy if 
> you could tell me a workaround (i.e. different invocation of py.test, without 
> changing the directory name of course).

The error message is a bit obscure but scrolling a bit up you see
that py.test tries to import  'io.something.test_foo' - i.e. you
have created a package 'io' and that overlaps with the standard library's
'io' package.  Solution: rename 'io' to something else (and generally
don't use a package name that overlaps with standard library ones). 

cheers,
holger



More information about the Pytest-dev mailing list