diff --git a/django/test/testcases.py b/django/test/testcases.py
index 0f76e11..a17bbdd 100644
a
|
b
|
class TransactionTestCase(SimpleTestCase):
|
416 | 416 | self._urlconf_setup() |
417 | 417 | mail.outbox = [] |
418 | 418 | |
| 419 | def _databases_names(self, include_mirrors=True): |
| 420 | # If the test case has a multi_db=True flag, act on all databases. |
| 421 | # Otherwise, just on the default DB. |
| 422 | if getattr(self, 'multi_db', False): |
| 423 | return [alias for alias in connections |
| 424 | if include_mirrors or not connections[alias].settings_dict['TEST_MIRROR']] |
| 425 | else: |
| 426 | return [DEFAULT_DB_ALIAS] |
| 427 | |
419 | 428 | def _reset_sequences(self, db_name): |
420 | 429 | conn = connections[db_name] |
421 | 430 | if conn.features.supports_sequence_reset: |
… |
… |
class TransactionTestCase(SimpleTestCase):
|
433 | 442 | transaction.commit_unless_managed(using=db_name) |
434 | 443 | |
435 | 444 | def _fixture_setup(self): |
436 | | # If the test case has a multi_db=True flag, act on all databases. |
437 | | # Otherwise, just on the default DB. |
438 | | db_names = connections if getattr(self, 'multi_db', False) else [DEFAULT_DB_ALIAS] |
439 | | for db_name in db_names: |
| 445 | for db_name in self._databases_names(include_mirrors=False): |
440 | 446 | # Reset sequences |
441 | 447 | if self.reset_sequences: |
442 | 448 | self._reset_sequences(db_name) |
… |
… |
class TransactionTestCase(SimpleTestCase):
|
502 | 508 | conn.close() |
503 | 509 | |
504 | 510 | def _fixture_teardown(self): |
505 | | # If the test case has a multi_db=True flag, flush all databases. |
506 | | # Otherwise, just flush default. |
507 | | databases = connections if getattr(self, 'multi_db', False) else [DEFAULT_DB_ALIAS] |
508 | | |
509 | 511 | # Roll back any pending transactions in order to avoid a deadlock |
510 | 512 | # during flush when TEST_MIRROR is used (#18984). |
511 | 513 | for conn in connections.all(): |
512 | 514 | conn.rollback_unless_managed() |
513 | 515 | |
514 | | for db in databases: |
| 516 | for db in self._databases_names(include_mirrors=False): |
515 | 517 | call_command('flush', verbosity=0, interactive=False, database=db, |
516 | 518 | skip_validation=True, reset_sequences=False) |
517 | 519 | |
… |
… |
class TestCase(TransactionTestCase):
|
796 | 798 | |
797 | 799 | assert not self.reset_sequences, 'reset_sequences cannot be used on TestCase instances' |
798 | 800 | |
799 | | # If the test case has a multi_db=True flag, setup all databases. |
800 | | # Otherwise, just use default. |
801 | | db_names = connections if getattr(self, 'multi_db', False) else [DEFAULT_DB_ALIAS] |
802 | | |
803 | | for db_name in db_names: |
| 801 | for db_name in self._databases_names(): |
804 | 802 | transaction.enter_transaction_management(using=db_name) |
805 | 803 | transaction.managed(True, using=db_name) |
806 | 804 | disable_transaction_methods() |
… |
… |
class TestCase(TransactionTestCase):
|
808 | 806 | from django.contrib.sites.models import Site |
809 | 807 | Site.objects.clear_cache() |
810 | 808 | |
811 | | for db in db_names: |
| 809 | for db in self._databases_names(include_mirrors=False): |
812 | 810 | if hasattr(self, 'fixtures'): |
813 | 811 | call_command('loaddata', *self.fixtures, |
814 | 812 | **{ |
… |
… |
class TestCase(TransactionTestCase):
|
822 | 820 | if not connections_support_transactions(): |
823 | 821 | return super(TestCase, self)._fixture_teardown() |
824 | 822 | |
825 | | # If the test case has a multi_db=True flag, teardown all databases. |
826 | | # Otherwise, just teardown default. |
827 | | if getattr(self, 'multi_db', False): |
828 | | databases = connections |
829 | | else: |
830 | | databases = [DEFAULT_DB_ALIAS] |
831 | | |
832 | 823 | restore_transaction_methods() |
833 | | for db in databases: |
| 824 | for db in self._databases_names(): |
834 | 825 | transaction.rollback(using=db) |
835 | 826 | transaction.leave_transaction_management(using=db) |
836 | 827 | |