Skip to content

Commit 0701798

Browse files
committed
Adding the ability to skip tests for certain django versions
1 parent 4f7a411 commit 0701798

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

test/test_func.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import unittest
55
from django.conf import settings
66
from pylint.testutils import make_tests, LintTestUsingFile, cb_test_gen, linter
7+
from pylint_django.compat import django_version
78

89

910
settings.configure()
@@ -20,6 +21,12 @@
2021
linter.global_set_option('disable', ('E0012',))
2122

2223

24+
SKIP_TESTS_FOR_DJANGO_VERSION = {
25+
# if the value of the dict key is False, skip the test, otherwise run it
26+
'func_noerror_protected_meta_access': django_version >= (1, 8)
27+
}
28+
29+
2330
def module_exists(module_name):
2431
try:
2532
__import__(module_name)
@@ -35,7 +42,22 @@ def tests(input_dir, messages_dir):
3542
input_dir = os.path.join(HERE, input_dir)
3643
messages_dir = os.path.join(HERE, messages_dir)
3744

38-
return make_tests(input_dir, messages_dir, None, callbacks)
45+
# first tests which pass for all Django versions
46+
tests = make_tests(input_dir, messages_dir, None, callbacks)
47+
48+
# now skip some tests test for specific versions - for example,
49+
# _meta access should not work for django<1.8 but should run and
50+
# pass for django 1.4 - skip the tests which will be checking
51+
# a piece of functionality in pylint-django that should only
52+
# in higher versions.
53+
specific_tests = []
54+
for test_name, version_range in SKIP_TESTS_FOR_DJANGO_VERSION.iteritems():
55+
if not version_range:
56+
specific_tests.append(test_name)
57+
filter_rgx = '(%s)' % '|'.join(specific_tests)
58+
59+
tests += make_tests(os.path.join(input_dir, 'versions'), messages_dir, filter_rgx, callbacks)
60+
return tests
3961

4062

4163
def suite():

0 commit comments

Comments
 (0)