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?
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With