Django reset_sequences not working in LiveServerTestCase

I have updated django from 1.6 to 1.8.3. I am creating test models in setUp method in unit tests, something like this

class MyTestCase(LiveServerTestCase):
    reset_sequences = True
    def setUp(self):
        self.my_model = models.MyModel.objects.create(name='test)

      

And I have code in my application that relies on primary key == 1. I noted that the sequences were not actually flushed. Each next test has more pk than the previous one.

This works fine in django 1.6, but after upgrading to 1.8, problems appear.

Do I have to reset the sequence manually?

Ps I know about fixtures, but my models are more complex and it is easier for me to create models in code.

+3


source to share


1 answer


The problem was sqlite3. The tests were run with a different settings file where sqlite3 is configured as a database.

Django check if the database supports sequences:



# django.test.testcases.py:809
def _reset_sequences(self, db_name):
    conn = connections[db_name]
    if conn.features.supports_sequence_reset:
        sql_list = conn.ops.sequence_reset_by_name_sql(
            no_style(), conn.introspection.sequence_list())
    # ....

      

So I switched the test settings to postgresql and now it works fine

+2


source







All Articles