[py-dev] Making py.test ignore an __init__.py

lahwran lahwran0 at gmail.com
Mon Dec 17 07:34:22 CET 2012


Hi, I've got a bit of a problem related to how pytest determines the fully
qualified name for a module. I have a django 1.3 layout project which has
an __init__.py at its root, due to oddities in how django functions. so I
have something like this layout:

~/project_venv/ # containing the virtualenv for the project
~/project_venv/project/ # the directory I cd to when I work
~/project_venv/project/.git
~/project_venv/project/__init__.py # because django's stuff doesn't work
without it
~/project_venv/project/applications/
~/project_venv/project/applications/__init__.py
~/project_venv/project/applications/projectapp/
~/project_venv/project/applications/projectapp/__init__.py
~/project_venv/project/applications/projectapp/some_file.py
~/project_venv/project/applications/projectapp/some_other_file.py
~/project_venv/project/applications/projectapp/tests/
~/project_venv/project/applications/projectapp/tests/__init__.py
~/project_venv/project/applications/projectapp/tests/test_some_file.py
~/project_venv/project/applications/projectapp/tests/test_some_other_file.py

in test_some_file.py, I have something like:

    from applications.projectapp.some_file import Herp, Derp, doop

and in test_some_other_file.py, I have something similar:

    from applications.projectapp.some_other_file import Herk, Derk, foo
    from applications.projectapp.tests.test_some_file import
SomeTestUtilityThingy

however, because project/ has an __init__.py, when pytest does its
collection, rather than importing
applications.projectapp.tests.test_some_file, it imports,
project.applications.projectapp.tests.test_some_file! worse, when
test_some_other_file.py imports test_some_file, it creates a *duplicate* -
the import creates an applications.projectapp.tests.test_some_file when
project.applications.projectapp.tests.test_some_file already existed.

so, my question is: how can I tell pytest to please just pretend that
__init__.py doesn't exist? right now I'm using conftest.py to shove
dirname(__file__) onto sys.path, but that was written before I thought to
check if there was an __init__.py in the root of the project.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20121216/d28167fe/attachment.html>


More information about the Pytest-dev mailing list