I have a number of Django tests and typically run them using py.test. I recently added a new test case in a new file test_selenium.py
. This Test Case has uses the LiveServerTestCase
and StaticLiveServerTestCase
classes (which is a first for me, usually I am using just TestCase
).
Adding this new batch of tests in this new file has caused subsequent tests to start failing in py.test (when before they all passed). It appears that the database is not being "reset" after the LiveServerTestCase
in py.test. I can tell because of the incrementation of my model's pk
values.
When I run these tests using the Django test runner, they all pass and the pk
's are reset in subsequent tests; in the py.test test runner the pk
's are being incremented in subsequent tests after the LiveServerTestCase
is run. So if I have hardcoded in my test to create an object and retrieve it based on the pk
I am expecting it fails because the databases are different between Django and py.test.
Any ideas why this might be and how to fix it?
New test test causing the DB behavior:
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
class UpdateCountSelenium(StaticLiveServerTestCase):
def setUp(self):
self.selenium = webdriver.Firefox()
self.delay = 3
def tearDown(self):
self.selenium.quit()
def test_ajax_hit(self):
self.selenium.get("%s%s" % (self.live_server_url, '/1/'))
# waits for javascript to load and tests the ajax view
wait = WebDriverWait(self.selenium, 3)
response = wait.until(EC.text_to_be_present_in_element((By.ID, 'counted-value'), 'true'))
self.assertTrue(response)