New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pytestbot opened this Issue Feb 28, 2013 · 4 comments

Comments

Projects
None yet
2 participants
@pytestbot

pytestbot commented Feb 28, 2013

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

@pytestbot

This comment has been minimized.

pytestbot commented Mar 15, 2013

Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt):


this is a tricky interaction of pythonpaths

due to your test layout there are 2 tests packages that are not namespaces

it would require a custom import system to propperly catch that
nose does some magic to keep test modules/packages kind of separate in importing

its up for consideration

@pytestbot

This comment has been minimized.

pytestbot commented Nov 22, 2013

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


add a note to the documentation that pytest does not mimick nose try to perform "import isolation". Addresses issue268.

@pytestbot

This comment has been minimized.

pytestbot commented Nov 22, 2013

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


This is really about allowing the same import path to map to different file system paths. This can lead to a number of problems and is the reason, i think, why nose2 dropped it, see https://nose2.readthedocs.org/en/latest/differences.html#test-discovery-and-loading

For now, i regard this issue as an "enhancement" and we may arrive at the conclusion to not support it. Depends also on further feedback.

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Dec 30, 2015

Closing as irrelevant

fkohlgrueber pushed a commit to fkohlgrueber/pytest that referenced this issue Oct 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment