Opened 6 years ago

Closed 5 years ago

#29513 closed Cleanup/optimization (fixed)

Make TransactionTestCase.multi_db documentation more discoverable.

Reported by: Adam Johnson Owned by: nobody
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I had a pull request that took me two years to resolve (okay, I deferred it quite a lot): https://github.com/adamchainz/django-mysql/pull/278 . This was adding pytest-randomly to my project, which randomly sorts the tests and exposes test interdependence. It turned out the failure was due to interdependence between tests that touched a secondary database, with the TestCase classes not resetting the secondary database, because multi_db=True was missing from such TestCases to get the secondary DB wiped between tests.

Part of the trouble debugging this was that multi_db is not easy to find:

I think we should fix the docs for these problems 🎉.

Secondarily, the feature is confusing and I'd flip the default of the flag to True and allow setting it to False as an optimization - but this is a much bigger change.

Change History (6)

comment:1 by Simon Charette, 6 years ago

#28478 is related.

It suggests merging multi_db and allow_database_queries flags into a single databases aliases set that would be unionized to determine which databases needs to be created based on the tests retrieved during discovery.

When a query to an unspecified database would be performed an error similar to the one raised when performing queries in a SimpleTestCase right now would be raised. SimpleTestCase.databases would be an empty set while TestCase.databases = {DEFAULT_DB_ALIAS}. multi_db = True could be alias for databases = {alias for alias in connections} during the deprecation period. We could also support a special databases = '__all__' value to replicate the actual multi_db behavior.

Here's the PoC.

comment:2 by Tim Graham, 6 years ago

Component: Testing frameworkDocumentation
Summary: Improve testing multi_db documentationMake TransactionTestCase.multi_db documentation for discoverable
Triage Stage: UnreviewedAccepted

comment:3 by Adam Johnson, 6 years ago

Summary: Make TransactionTestCase.multi_db documentation for discoverableMake TransactionTestCase.multi_db documentation more discoverable

comment:4 by Tim Graham <timograham@…>, 6 years ago

In 2a01162:

Refs #29513 -- Linked the testing docs from the multi-db topic guide.

comment:5 by Tim Graham <timograham@…>, 6 years ago

In db287e99:

[2.1.x] Refs #29513 -- Linked the testing docs from the multi-db topic guide.

Backport of 2a0116266c4d81bd1cc4e3ea20efe9a7874f481b from master

comment:6 by Mariusz Felisiak, 5 years ago

Resolution: fixed
Status: newclosed
Summary: Make TransactionTestCase.multi_db documentation more discoverableMake TransactionTestCase.multi_db documentation more discoverable.

We can treat this ticket as fixed, since multi_db will be removed in Django 3.1 (see b61ea56789a5825bd2961a335cb82f65e09f1614).

Note: See TracTickets for help on using tickets.
Back to Top