Opened 4 months ago
Closed 4 months ago
#35722 closed Cleanup/optimization (wontfix)
Specify behaviour in TransactionTestCase.reset_sequences
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 )
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 (3)
comment:1 by , 4 months ago
Description: | modified (diff) |
---|
follow-up: 3 comment:2 by , 4 months ago
comment:3 by , 4 months ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Replying to Simon Charette:
...a
subTest
context is solely a manner to annotate part of a test case method body with some context.
Exactly - subTest
is a unittest feature, not a Django feature, and any setUp()
or tearDown()
etc happens per test (not per subTest
). The reset_sequences
behavior is consistent to this. Hence, I don't think we need to add documentation to Django on this
If we are to add a note about subTest, I'm not entirely convinced it's needed, I believe we should only focus on the behavior of
reset_sequences
but all the database isolation features thatTransactionTestCase
andTestCase
does provide within the context of distincttest_
method. In other words, no persubTest
data isolation (sequence, transactions, mailbox, etc) is implemented and within the context of aTransactionTestCase
and friends asubTest
context is solely a manner to annotate part of a test case method body with some context.