Fixed #23469 -- Removed test runner compatibility check which often yielded false positives.
This commit is contained in:
parent
6ce6c77e03
commit
7ae03204ac
|
@ -9,85 +9,10 @@ from .. import Warning, register, Tags
|
||||||
@register(Tags.compatibility)
|
@register(Tags.compatibility)
|
||||||
def check_1_6_compatibility(**kwargs):
|
def check_1_6_compatibility(**kwargs):
|
||||||
errors = []
|
errors = []
|
||||||
errors.extend(_check_test_runner(**kwargs))
|
|
||||||
errors.extend(_check_boolean_field_default_value(**kwargs))
|
errors.extend(_check_boolean_field_default_value(**kwargs))
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
|
|
||||||
def _check_test_runner(app_configs=None, **kwargs):
|
|
||||||
"""
|
|
||||||
Checks if the user has *not* overridden the ``TEST_RUNNER`` setting &
|
|
||||||
warns them about the default behavior changes.
|
|
||||||
|
|
||||||
If the user has overridden that setting, we presume they know what they're
|
|
||||||
doing & avoid generating a message.
|
|
||||||
"""
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
# We need to establish if this is a project defined on the 1.5 project template,
|
|
||||||
# because if the project was generated on the 1.6 template, it will have be been
|
|
||||||
# developed with the new TEST_RUNNER behavior in mind.
|
|
||||||
|
|
||||||
# There's no canonical way to do this; so we leverage off the fact that 1.6
|
|
||||||
# also introduced a new project template, removing a bunch of settings from the
|
|
||||||
# default that won't be in common usage.
|
|
||||||
|
|
||||||
# We make this determination on a balance of probabilities. Each of these factors
|
|
||||||
# contributes a weight; if enough of them trigger, we've got a likely 1.6 project.
|
|
||||||
weight = 0
|
|
||||||
|
|
||||||
# If TEST_RUNNER is explicitly set, it's all a moot point - if it's been explicitly set,
|
|
||||||
# the user has opted into a specific set of behaviors, which won't change as the
|
|
||||||
# default changes.
|
|
||||||
if not settings.is_overridden('TEST_RUNNER'):
|
|
||||||
# Strong markers:
|
|
||||||
# SITE_ID = 1 is in 1.5 template, not defined in 1.6 template
|
|
||||||
try:
|
|
||||||
settings.SITE_ID
|
|
||||||
weight += 2
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# BASE_DIR is not defined in 1.5 template, set in 1.6 template
|
|
||||||
try:
|
|
||||||
settings.BASE_DIR
|
|
||||||
except AttributeError:
|
|
||||||
weight += 2
|
|
||||||
|
|
||||||
# TEMPLATE_LOADERS defined in 1.5 template, not defined in 1.6 template
|
|
||||||
if settings.is_overridden('TEMPLATE_LOADERS'):
|
|
||||||
weight += 2
|
|
||||||
|
|
||||||
# MANAGERS defined in 1.5 template, not defined in 1.6 template
|
|
||||||
if settings.is_overridden('MANAGERS'):
|
|
||||||
weight += 2
|
|
||||||
|
|
||||||
# Weaker markers - These are more likely to have been added in common usage
|
|
||||||
# ADMINS defined in 1.5 template, not defined in 1.6 template
|
|
||||||
if settings.is_overridden('ADMINS'):
|
|
||||||
weight += 1
|
|
||||||
|
|
||||||
# Clickjacking enabled by default in 1.6
|
|
||||||
if 'django.middleware.clickjacking.XFrameOptionsMiddleware' not in set(settings.MIDDLEWARE_CLASSES):
|
|
||||||
weight += 1
|
|
||||||
|
|
||||||
if weight >= 6:
|
|
||||||
return [
|
|
||||||
Warning(
|
|
||||||
"Some project unittests may not execute as expected.",
|
|
||||||
hint=("Django 1.6 introduced a new default test runner. It looks like "
|
|
||||||
"this project was generated using Django 1.5 or earlier. You should "
|
|
||||||
"ensure your tests are all running & behaving as expected. See "
|
|
||||||
"https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner "
|
|
||||||
"for more information."),
|
|
||||||
obj=None,
|
|
||||||
id='1_6.W001',
|
|
||||||
)
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
return []
|
|
||||||
|
|
||||||
|
|
||||||
def _check_boolean_field_default_value(app_configs=None, **kwargs):
|
def _check_boolean_field_default_value(app_configs=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Checks if there are any BooleanFields without a default value, &
|
Checks if there are any BooleanFields without a default value, &
|
||||||
|
|
|
@ -166,7 +166,8 @@ Backwards Compatibility
|
||||||
The following checks are performed to warn the user of any potential problems
|
The following checks are performed to warn the user of any potential problems
|
||||||
that might occur as a result of a version upgrade.
|
that might occur as a result of a version upgrade.
|
||||||
|
|
||||||
* **1_6.W001**: Some project unit tests may not execute as expected.
|
* **1_6.W001**: Some project unit tests may not execute as expected. *This
|
||||||
|
check was removed in Django 1.8 due to false positives*.
|
||||||
* **1_6.W002**: ``BooleanField`` does not have a default value.
|
* **1_6.W002**: ``BooleanField`` does not have a default value.
|
||||||
|
|
||||||
Admin
|
Admin
|
||||||
|
|
|
@ -86,47 +86,6 @@ class MessageTests(TestCase):
|
||||||
|
|
||||||
class Django_1_6_0_CompatibilityChecks(TestCase):
|
class Django_1_6_0_CompatibilityChecks(TestCase):
|
||||||
|
|
||||||
@override_settings(TEST_RUNNER='django.test.runner.DiscoverRunner')
|
|
||||||
def test_test_runner_new_default(self):
|
|
||||||
errors = check_1_6_compatibility()
|
|
||||||
self.assertEqual(errors, [])
|
|
||||||
|
|
||||||
@override_settings(TEST_RUNNER='myapp.test.CustomRunner')
|
|
||||||
def test_test_runner_overriden(self):
|
|
||||||
errors = check_1_6_compatibility()
|
|
||||||
self.assertEqual(errors, [])
|
|
||||||
|
|
||||||
def test_test_runner_not_set_explicitly(self):
|
|
||||||
# If TEST_RUNNER was set explicitly, temporarily pretend it wasn't
|
|
||||||
test_runner_overridden = False
|
|
||||||
if 'TEST_RUNNER' in settings._wrapped._explicit_settings:
|
|
||||||
test_runner_overridden = True
|
|
||||||
settings._wrapped._explicit_settings.remove('TEST_RUNNER')
|
|
||||||
# We remove some settings to make this look like a project generated under Django 1.5.
|
|
||||||
settings._wrapped._explicit_settings.add('MANAGERS')
|
|
||||||
settings._wrapped._explicit_settings.add('ADMINS')
|
|
||||||
try:
|
|
||||||
errors = check_1_6_compatibility()
|
|
||||||
expected = [
|
|
||||||
checks.Warning(
|
|
||||||
"Some project unittests may not execute as expected.",
|
|
||||||
hint=("Django 1.6 introduced a new default test runner. It looks like "
|
|
||||||
"this project was generated using Django 1.5 or earlier. You should "
|
|
||||||
"ensure your tests are all running & behaving as expected. See "
|
|
||||||
"https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner "
|
|
||||||
"for more information."),
|
|
||||||
obj=None,
|
|
||||||
id='1_6.W001',
|
|
||||||
)
|
|
||||||
]
|
|
||||||
self.assertEqual(errors, expected)
|
|
||||||
finally:
|
|
||||||
# Restore settings value
|
|
||||||
if test_runner_overridden:
|
|
||||||
settings._wrapped._explicit_settings.add('TEST_RUNNER')
|
|
||||||
settings._wrapped._explicit_settings.remove('MANAGERS')
|
|
||||||
settings._wrapped._explicit_settings.remove('ADMINS')
|
|
||||||
|
|
||||||
@override_settings(TEST_RUNNER='myapp.test.CustomRunner')
|
@override_settings(TEST_RUNNER='myapp.test.CustomRunner')
|
||||||
def test_boolean_field_default_value(self):
|
def test_boolean_field_default_value(self):
|
||||||
# We patch the field's default value to trigger the warning
|
# We patch the field's default value to trigger the warning
|
||||||
|
|
Loading…
Reference in New Issue