3

I'm trying to test my django project, I have an app with a very classic layout like so :

project
├── __init__.py
└── app
    ├── __init__.py
    ├── models.py
    ├── tests
    │   ├── __init__.py
    │   ├── models.py
    │   └── views.py
    └── views.py

with manage.py in the parent directory of manage.py (according to django 1.4 new layout).

in tests/__init__.py I have something like that :

from project.app.tests.models import *
from project.app.tests.views import *

in tests/models.py I have classic python tests (which work just fine), and in tests/views.py I have selenium tests.

Now when I do :

python manage.py test project/app/tests/views.py

The selenium tests work without any problem (well they fail for now but I'm working on that). BUT when I do :

python manage.py test project/app

Some regular tests are launch correctly but at some point, firefox is launch and everything just freeze, no more test are launch, nothing is happening in firefox nor in the terminal.

I would add that my regular tests derive from unittest.TestCase (not django.test.TestCase), that my selenium tests derive from django.test.LiveServerTestCase, and that I'm using django 1.4.0, nose 1.2.1, django-nose 1.1 and selenium 2.26.0.

Any clue ?

Michaël
  • 63
  • 1
  • 4
  • did you ever find a solution to this? I am experiencing the same behavior with selenium tests that work just fine when using Django's built-in test runner (instead of django-nose). – ppetrid Jan 29 '13 at 23:09
  • Actually I was using two databases when I posted this question, and for various reasons I stopped, which solved my problem. But I never understood was really going on at that point. – Michaël Feb 04 '13 at 15:17

2 Answers2

0

If you are using selenium's wait methods there is potential for tests to be blocked until a particular condition is met. See webdriver document above.

Brian Cajes
  • 3,274
  • 3
  • 21
  • 22
  • Actually I'm not using such methods, but when I do : self.selenium.get(url) self.selenium.find_element_by_name(my_submit_name).click() There is no problem at all, which would suggest that selenium implicity waits for something ? – Michaël Nov 23 '12 at 17:28
  • Using the click method waits for page to be fully loaded. If there is an issue loading the page, the method can wait indefinitely. You will want to set a pageload timeout via the set_page_load_timeout method: http://selenium.googlecode.com/svn/trunk/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html?highlight=timeout#selenium.webdriver.remote.webdriver.WebDriver.set_page_load_timeout – Brian Cajes Nov 23 '12 at 18:23
0

I have read somewhere (forgot the source of this) that the combination you are using, needs a test database alias for sqlite (TEST_NAME). and not to use the in-memory sqlite database. Not sure what database you are using while testing, but maybe this information helps?

I put this in my development settings:

DATABASES = {
    'default': {
        'NAME': os.path.join(BUILDOUT_DIR, 'var', 'sqlite', 'development.db'),
        # TEST_NAME is absolutely CRITICAL for getting django-nose-selenium
        # going with sqlite3. The default in-memory breaks everything.
        'TEST_NAME': os.path.join(BUILDOUT_DIR, 'var', 'sqlite', 'unittest.db'),
        'ENGINE': 'django.db.backends.sqlite3', 
        'USER': '',
        'PASSWORD': '',
        'HOST': '',  # empty string for localhost.
        'PORT': '',  # empty string for default.
        }
    }
michel.iamit
  • 5,788
  • 9
  • 55
  • 74