Opened 7 months ago
Last modified 7 months ago
#36313 closed Bug
even with `reset_sequences=True` a class does not reset them on teardown — at Initial Version
| Reported by: | anthony sottile | Owned by: | |
|---|---|---|---|
| Component: | Testing framework | Version: | dev |
| Severity: | Normal | Keywords: | reset_sequences |
| Cc: | Jacob Walls | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I have a particular test class which I know breaks primary key ordering for a bunch of other tests in the process. I figured I could extend TransactionTestCase and set reset_sequences = True on this class but the sequence state persists after the test
seems this was improved in https://code.djangoproject.com/ticket/18271
I believe this minimal patch would fix it :
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 8f9ba977a3..e2cf63b56d 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -1239,7 +1239,7 @@ class TransactionTestCase(SimpleTestCase):
verbosity=0,
interactive=False,
database=db_name,
- reset_sequences=False,
+ reset_sequences=cls.reset_sequences,
allow_cascade=self.available_apps is not None,
inhibit_post_migrate=inhibit_post_migrate,
)
I'm specifically using django 5.1.7 but given the code this also affects the in-development version
Note:
See TracTickets
for help on using tickets.