Django LiveServerTestCase fails to load a page when I run multiple tests Django LiveServerTestCase fails to load a page when I run multiple tests selenium selenium

Django LiveServerTestCase fails to load a page when I run multiple tests


Finally, the reason for the "internal server error" message is that WebDriver deletes all data from database on quit(), including contenttypes and other default tables.

This leads to an error when trying to load fixtures at the begin of the next test.

N.B. This behaviour is actually due to the way TransactionTestCase (from which LiveServerTestCase inherits) resets the database after the test runs: it truncates all tables.


So far, my solution is to load fixtures with all the data (also "default" Django data, e.g. contenttypes) on every test run.

class MyLiveServerTestCase(LiveServerTestCase):        """    BaseClass for my Selenium test cases    """    fixtures = ['my_fixture_with_all_default_stuff_and_testing_data.json']    @classmethod    def setUpClass(cls):        cls.driver = WebDriver()        cls.url = cls.live_server_url            super(MyLiveServerTestCase, cls).setUpClass()    @classmethod    def tearDownClass(cls):        cls.driver.quit()        super(MyLiveServerTestCase, cls).tearDownClass()

Thanks to @help_asap for pointing out this flushing database on quit() problem!