[py-dev] failing import in toplevel module

Carl Friedrich Bolz cfbolz at gmx.de
Tue Nov 15 23:19:51 CET 2005

Hi py-dev!

today I had the following problem with py.test: I could not find a way 
to skip tests in a package if the import of the package itself fails 
(because the __init__.py raises something). Example:

assuming I have a package directory "example" with two files in it:


something that can raise ImportError


import py

     import example
except ImportError:
     py.test.skip("missing dependencies, whatever")

... (some tests)

In this situation the tests will always fail because py.test 
automatically tries to import the top-level package. This cannot be 
circumvented even when using a conftest file since the import of the 
top-level package happens very early.

Is there something I was missing? Couldn't for example py.test only 
insert the path to the top-level dir into sys.path, so that the "import 
example" find the correct package?


Carl Friedrich

More information about the Pytest-dev mailing list