Skip to content

Instantly share code, notes, and snippets.

@krya
Created December 5, 2012 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krya/4214583 to your computer and use it in GitHub Desktop.
Save krya/4214583 to your computer and use it in GitHub Desktop.
pytest conftest confusion
~$ mkvirtualenv myproject
New python executable in myproject/bin/python
Installing setuptools............done.
Installing pip...............done.
virtualenvwrapper.user_scripts creating /opt/env/myproject/bin/predeactivate
virtualenvwrapper.user_scripts creating /opt/env/myproject/bin/postdeactivate
virtualenvwrapper.user_scripts creating /opt/env/myproject/bin/preactivate
virtualenvwrapper.user_scripts creating /opt/env/myproject/bin/postactivate
virtualenvwrapper.user_scripts creating /opt/env/myproject/bin/get_env_details
(myproject)~$ pip install django pytest-django
Downloading/unpacking django
Downloading Django-1.4.2.tar.gz (7.7Mb): 7.7Mb downloaded
Running setup.py egg_info for package django
Downloading/unpacking pytest-django
Downloading pytest-django-2.0.0.tar.gz
Running setup.py egg_info for package pytest-django
Downloading/unpacking pytest>=2.3.4 (from pytest-django)
Downloading pytest-2.3.4.zip (527Kb): 527Kb downloaded
Running setup.py egg_info for package pytest
Downloading/unpacking py>=1.4.12 (from pytest>=2.3.4->pytest-django)
Downloading py-1.4.12.zip (227Kb): 227Kb downloaded
Running setup.py egg_info for package py
Installing collected packages: django, pytest-django, pytest, py
Running setup.py install for django
changing mode of build/scripts-2.7/django-admin.py from 664 to 775
changing mode of /opt/env/myproject/bin/django-admin.py to 775
Running setup.py install for pytest-django
Running setup.py install for pytest
Installing py.test script to /opt/env/myproject/bin
Installing py.test-2.7 script to /opt/env/myproject/bin
Running setup.py install for py
Successfully installed django pytest-django pytest py
Cleaning up...
(myproject)~$ django-admin.py startproject myproject
(myproject)~$ cd myproject/
(myproject)~/myproject$ export DJANGO_SETTINGS_MODULE=myproject.settings
(myproject)~/myproject$ py.test
ERROR: Could not import settings 'myproject.settings' (Is it on sys.path?): No module named myproject.settings
(myproject)~/myproject$ touch conftest.py
(myproject)~/myproject$ py.test
========================================== test session starts ==========================================
platform linux2 -- Python 2.7.3 -- pytest-2.3.4
plugins: django
collected 0 items
=========================================== in 0.01 seconds ============================================
(myproject)~/myproject$ rm conftest*
(myproject)~/myproject$ echo "import pytest
> pytestmark = pytest.mark.django_db
> def test_project(): assert 1
> " > test_project.py
(myproject)~/myproject$ py.test
ERROR: Could not import settings 'myproject.settings' (Is it on sys.path?): No module named myproject.settings
(myproject)~/myproject$ touch conftest.py
(myproject)~/myproject$ py.test
================================================== test session starts ===================================================
platform linux2 -- Python 2.7.3 -- pytest-2.3.4
plugins: django
collected 1 items
test_project.py .
================================================ 1 passed in 0.29 seconds ================================================
(myproject)~/myproject$ python manage.py startapp myapp
(myproject)~/myproject$ echo "def test_app():assert 1" > myapp/test_app.py
(myproject)~/myproject$ py.test
================================================== test session starts ===================================================
platform linux2 -- Python 2.7.3 -- pytest-2.3.4
plugins: django
collected 2 items
test_project.py .
myapp/test_app.py .
================================================ 2 passed in 0.21 seconds ================================================
(myproject)~/myproject$ rm conftest*
(myproject)~/myproject$ py.test
ERROR: Could not import settings 'myproject.settings' (Is it on sys.path?): No module named myproject.settings
(myproject)~/myproject$ ls . myapp
.:
итого 56
drwxrwxr-x 5 krya krya 4096 Дек 5 12:23 .
drwxr-xr-x 96 krya krya 32768 Дек 5 12:08 ..
-rw-rw-r-- 1 krya krya 252 Дек 5 12:08 manage.py
drwxrwxr-x 3 krya krya 4096 Дек 5 12:22 myapp
drwxrwxr-x 2 krya krya 4096 Дек 5 12:16 myproject
drwxrwxr-x 2 krya krya 4096 Дек 5 12:14 __pycache__
-rw-rw-r-- 1 krya krya 79 Дек 5 12:14 test_project.py
myapp:
итого 32
drwxrwxr-x 3 krya krya 4096 Дек 5 12:22 .
drwxrwxr-x 5 krya krya 4096 Дек 5 12:23 ..
-rw-rw-r-- 1 krya krya 0 Дек 5 12:19 __init__.py
-rw-rw-r-- 1 krya krya 125 Дек 5 12:22 __init__.pyc
-rw-rw-r-- 1 krya krya 57 Дек 5 12:19 models.py
drwxrwxr-x 2 krya krya 4096 Дек 5 12:22 __pycache__
-rw-rw-r-- 1 krya krya 24 Дек 5 12:20 test_app.py
-rw-rw-r-- 1 krya krya 383 Дек 5 12:19 tests.py
-rw-rw-r-- 1 krya krya 26 Дек 5 12:19 views.py
(myproject)~/myproject$ cat test_project.py
import pytest
pytestmark = pytest.mark.django_db
def test_project(): assert 1
(myproject)~/myproject$ cat myapp/test_app.py
def test_app():assert 1
(myproject)~/myproject$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment