mirror of
https://github.com/django/django.git
synced 2025-08-30 07:17:49 +00:00
Fixed #25746 -- Isolated inlined test models registration.
Thanks to Tim for the review.
This commit is contained in:
parent
3096f4b082
commit
a08fda2111
29 changed files with 285 additions and 371 deletions
|
@ -11,7 +11,9 @@ from django.core.management import call_command
|
|||
from django.core.management.base import CommandError
|
||||
from django.db import models
|
||||
from django.test import SimpleTestCase
|
||||
from django.test.utils import override_settings, override_system_checks
|
||||
from django.test.utils import (
|
||||
isolate_apps, override_settings, override_system_checks,
|
||||
)
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.six import StringIO
|
||||
|
||||
|
@ -254,23 +256,10 @@ class SilencingCheckTests(SimpleTestCase):
|
|||
self.assertEqual(err.getvalue(), '')
|
||||
|
||||
|
||||
class IsolateModelsMixin(object):
|
||||
def setUp(self):
|
||||
self.current_models = apps.all_models[__package__]
|
||||
self.saved_models = set(self.current_models)
|
||||
|
||||
def tearDown(self):
|
||||
for model in (set(self.current_models) - self.saved_models):
|
||||
del self.current_models[model]
|
||||
apps.clear_cache()
|
||||
|
||||
|
||||
class CheckFrameworkReservedNamesTests(IsolateModelsMixin, SimpleTestCase):
|
||||
@override_settings(
|
||||
SILENCED_SYSTEM_CHECKS=['models.E20', 'fields.W342'], # ForeignKey(unique=True)
|
||||
INSTALLED_APPS=['django.contrib.auth', 'django.contrib.contenttypes', 'check_framework']
|
||||
)
|
||||
def test_model_check_method_not_shadowed(self):
|
||||
class CheckFrameworkReservedNamesTests(SimpleTestCase):
|
||||
@isolate_apps('check_framework', kwarg_name='apps')
|
||||
@override_system_checks([checks.model_checks.check_all_models])
|
||||
def test_model_check_method_not_shadowed(self, apps):
|
||||
class ModelWithAttributeCalledCheck(models.Model):
|
||||
check = 42
|
||||
|
||||
|
@ -288,7 +277,7 @@ class CheckFrameworkReservedNamesTests(IsolateModelsMixin, SimpleTestCase):
|
|||
related_name='check',
|
||||
)
|
||||
|
||||
errors = checks.run_checks()
|
||||
errors = checks.run_checks(app_configs=apps.get_app_configs())
|
||||
expected = [
|
||||
Error(
|
||||
"The 'ModelWithAttributeCalledCheck.check()' class method is "
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue