Skip to content

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

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

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

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

pytestbot opened this issue Feb 28, 2013 · 4 comments
Labels
type: enhancement new feature or API change, should be merged into features branch

Comments

@pytestbot
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@pytestbot pytestbot added the type: enhancement new feature or API change, should be merged into features branch label Jun 15, 2015
@RonnyPfannschmidt
Copy link
Member

Closing as irrelevant

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

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

2 participants