Code

Opened 2 years ago

Closed 21 months ago

#18271 closed Cleanup/optimization (fixed)

Make TransactionTestCase flush tables after test run instead of before

Reported by: andreas_pelme Owned by: nobody
Component: Testing framework Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

TransactionTestCase does not clean up after a test is run. When the next TransactionTestCase is run, tables are flushed and fixtures are loaded.

It would be better if the flush took place in _post_teardown, which would leave the database in a clean state after each test. Then test order does not matter, TransactionTestCase and TestCases can be executed in arbitrary order.

There is a related ticket #12408 to reorder doctests to also run before TransactionTestCase. If TransactionTestCase is changed, no reordering will be necessary.

django-developers discussion: http://groups.google.com/group/django-developers/browse_thread/thread/3df2b4926eba08d2?hl=en

Attachments (0)

Change History (3)

comment:1 Changed 2 years ago by andreas_pelme

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Initial patch is available as a pull request:

https://github.com/django/django/pull/45

Last edited 2 years ago by andreas_pelme (previous) (diff)

comment:2 Changed 2 years ago by akaariai

  • Component changed from Uncategorized to Testing framework
  • Triage Stage changed from Unreviewed to Design decision needed

I am going to mark this design decision needed. I do think this is a good idea, but there are two problems:

  1. If a test case screws up cleanup it will cause problems for itself currently, after the patch it will cause problems for the next test case which makes debugging much harder.
  2. Is this somehow backwards incompatible. The behavior was documented.

I think neither of the above is a blocker issue. The first issue can be annoying, but is is pretty much there already - if the cleanup doesn't work correctly, the breakage will be dependent on the previous test case anyways. I can't come up with any reason why moving the flush from before to after would be an issue... The backwards compatibility does need more investigation, though.

The main reason why I am marking this DDN is that maybe there was some reason why the flush was ran before the tests. So, lets keep this in DDN until everybody has had time to participate in the django-developers thread. If there are no objections in a week or so I am fine with moving this forward.

comment:3 Changed 21 months ago by Ramiro Morales <cramm0@…>

  • Resolution set to fixed
  • Status changed from new to closed

In [f758bdab5eec3e615598948dd5bcf9bb7b910c9d]:

Fixed #18271 -- Changed stage at which TransactionTestCase flushes DB tables.

Previously, the flush was done before the test case execution and now
it is performed after it.

Other changes to the testing infrastructure include:

  • TransactionTestCase now doesn't reset autoincrement sequences either (previous behavior can achieved by using reset_sequences.) With this, no implicit such reset is performed by any of the provided TestCase classes.
  • New ordering of test cases: All unittest tes cases are run first and doctests are run at the end.

THse changes could be backward-incompatible with test cases that relied
on some kind of state being preserved between tests. Please read the
relevant sections of the release notes and testing documentation for
further details.

Thanks Andreas Pelme for the initial patch. Karen Tracey and Anssi
Kääriäinen for the feedback and Anssi for reviewing.

This also fixes #12408.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.