Short:
I want to run Selenium tests during Django's unit tests.
When 'manage.py test' is running, there's no dev server available
for Selenium.
If I run my Django app separately, changes to the database are
cumulative instead of discrete, like Django's own tests.
My current solution:
I have a bash script that re-loads my local database from my test
fixtures then runs my app (via gunicorn) in the background.
Then I run 'manage.py test' and my tests (including the Selenium
tests) run.
Afterwards, my bash script sends a 'kill' command to the process ID
of my gunicorn script.
This works, but:
The Selenium tests each run from the same database, so db changes
are cumulative.
I have to create the database each time, separate from the one
Django's TestCase instances are using.
This also replaces my local development database each time, which
isn't a problem because I reload it from the fixtures regularly anyway,
but is mildly inconvenient.
Alternative method:
It's possible to use subprocess in a TestCase setUp and tearDown to
launch the Django dev server each time. This fixes the fixture refresh
issue.
However, this requires a separate settings.py file for testing to
set the "default" database settings to what the real settings.py file
uses for the test database.
I don't like this solution because it makes it impossible to use an
in-memory sqlite3 database and the interaction with the command line via
subprocess gets messy.
I found django-nose-selenium via a Google search, but it requires the
Java Selenium server to be running. It also adds a lot of extra stuff to
my project: installed apps, extra settings, extra command-line commands
required, and more complicated TestCases. I'm just using the Selenium
webdriver in a unittest.TestCase and it works great without any of that.
I don't want to add all that complexity just to get fresh fixtures for
each test.
Thanks,
Shawn
Thanks for the reply. I read the history of that ticket and it is
exactly what I'm looking for. Too bad it's five years in the making and
still not in trunk.
So, what did you do, use one of the patches in the ticket? If so, which
one? If you have a snippet or something then please post to the list --
it may be helpful to others.
Thanks,
Shawn