Opened 3 weeks ago

Last modified 3 weeks ago

#35722 closed Cleanup/optimization

Specify behaviour in TransactionTestCase.reset_sequences — at Version 1

Reported by: Slava M. Owned by:
Component: Documentation Version: dev
Severity: Normal Keywords: docs, test, documentation
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Slava M.)

https://docs.djangoproject.com/en/dev/topics/testing/advanced/#django.test.TransactionTestCase.reset_sequences

I suggest specifying behaviour of TransactionTestCase.reset_sequences when used in subtests https://docs.python.org/3/library/unittest.html#distinguishing-test-iterations-using-subtests.

i.e.

class TestsThatDependsOnPrimaryKeySequences(TransactionTestCase):
    reset_sequences = True

    def test_animal_pk(self):
        with self.subTest():
            lion = Animal.objects.create(name="lion", sound="roar")
            self.assertEqual(lion.pk, 1)
        with self.subTest():
            cat = Animal.objects.create(name="cat", sound="meow")
            # will this still work?
            self.assertEqual(cat.pk, 1)

add to documentation 1 sentence along the lines of:

  • "reset_sequences won't work with unittest's subTest()"
  • or ""reset_sequences also works with unittest's subTest()"

Change History (1)

comment:1 by Slava M., 3 weeks ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top