6

So I am experimenting with the introduction of selenium unit tests in django 1.4 in a couple of projects I am working on.

The standard way to run my unit tests are simply to do ./manage.py test and I use django-ignoretests to exclude specific django apps that I do not want tested (as needed).

However, is there a way to configure my project so that I can decide to run only selenium tests when I want to and have ./manage.py test run only standard unit tests.

What are some best practices for segregating and organizing selenium tests and standard unit tests?

Calvin Cheng
  • 35,640
  • 39
  • 116
  • 167

2 Answers2

5

You could always group all your selenium tests under a single package myapp/selenium_tests/ (as described here https://stackoverflow.com/a/5160779/1138710 for instance) and then run manage.py test myapp.selenium_tests and group the rest of tests under say myapp/other_tests.

Otherwise, I suppose you could write a test runner that checks for each test class whether it derives from LiveServerTestCase (see the docs: https://docs.djangoproject.com/en/dev/topics/testing/#defining-a-test-runner)

Community
  • 1
  • 1
Laurent S
  • 4,106
  • 3
  • 26
  • 50
  • As Selenium tests tend to be functional, I try to do the same, keeping them in a separate package, along with an option to skip them (http://stackoverflow.com/a/10743466/4281). I like the idea of the test runner, but in some cases the tests may not be a descendant of LiveServerTestCase (which is another issue). – Kris Kumler May 24 '12 at 18:46
5

For the test classes in question, I added the following decorator:

from django.conf import settings
@unittest.skipIf(getattr(settings,'SKIP_SELENIUM_TESTS', False), "Skipping Selenium tests")  

Then to skip those tests add to the settings file: SKIP_SELENIUM_TESTS = True

This could easily be wrapped into a subclass of LiveServerTestCase or a simple decorator. If I had that in more than one place, it would be already.

Kris Kumler
  • 6,307
  • 3
  • 24
  • 27