Skip to content

isolation when importing test modules (nose-style) #268

@pytestbot

Description

@pytestbot

Originally reported by: BitBucket: devtty0, GitHub: devtty0


I have a problem with multiple test dirs (find an example attached).

I have the following project structure:

basedir/ 
       /app/__init__.py
              *.py
       tests/__init__.py
               *.py
       core/ /** git submodule **/
              corelib/__init__.py
                         *.py
              tests/*.py
basedir $ PYTHONPATH=.:core:$PYTHONPATH py.test tests core/tests/
================================================================ test session starts =================================================================
platform linux2 -- Python 2.7.3 -- pytest-2.3.4
collected 1 items / 1 errors 

tests/test_id.py .

======================================================================= ERRORS =======================================================================
______________________________________________________ ERROR collecting core/tests/test_sum.py _______________________________________________________
venv/lib/python2.7/site-packages/py/_path/local.py:532: in pyimport
>           __import__(modname)
E           ImportError: No module named test_sum
========================================================= 1 passed, 1 error in 0.05 seconds ==========================================================
basedir $ PYTHONPATH=.:core:$PYTHONPATH py.test tests
================================================================ test session starts =================================================================
platform linux2 -- Python 2.7.3 -- pytest-2.3.4
collected 1 items 

tests/test_id.py .

============================================================== 1 passed in 0.04 seconds ==============================================================
basedir $ PYTHONPATH=.:core:$PYTHONPATH py.test core/tests/
================================================================ test session starts =================================================================
platform linux2 -- Python 2.7.3 -- pytest-2.3.4
collected 1 items 

core/tests/test_sum.py .

============================================================== 1 passed in 0.04 seconds ==============================================================

if i put __init__.py into core directory, py.test works well:

basedir $ touch core/__init__.py
basedir $ ./run_pytest.sh 
================================================================ test session starts =================================================================
platform linux2 -- Python 2.7.3 -- pytest-2.3.4
collected 2 items 

tests/test_id.py .
core/tests/test_sum.py .

============================================================== 2 passed in 0.04 seconds ==============================================================

Nose works fine without __init__.py in core directory:

$ PYTHONPATH=.:core:$PYTHONPATH nosetests tests core/tests/
..
----------------------------------------------------------------------
Ran 2 tests in 0.001s

OK
$ py.test --version
This is py.test version 2.3.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions