Skip to content

Commit 5eb0a61

Browse files
committed
Update the way we load tests
this mimics more closely what pylint does for their own tests and doesn't rely on deprecated functionality. Fixes pylint-dev#107 and pylint-dev#97 Obsoletes pylint-dev#98
1 parent d890dcd commit 5eb0a61

File tree

1 file changed

+20
-57
lines changed

1 file changed

+20
-57
lines changed

test/test_func.py

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,36 @@
11

22
import os
33
import sys
4-
import unittest
5-
from django.conf import settings
6-
from pylint.testutils import make_tests, LintTestUsingFile, cb_test_gen, linter
4+
import pytest
5+
from pylint.testutils import linter
6+
from pylint.test import test_functional
77
from pylint_django.compat import django_version
88

9-
10-
settings.configure()
11-
12-
13-
HERE = os.path.dirname(os.path.abspath(__file__))
14-
15-
169
linter.load_plugin_modules(['pylint_django'])
17-
# Disable some things on Python2.6, since we use a different pylint version here
18-
# (1.3 on Python2.6, 1.4+ on later versions)
19-
if sys.version_info < (2, 7):
20-
linter.global_set_option('required-attributes', ())
21-
linter.global_set_option('disable', ('E0012',))
22-
23-
24-
SKIP_TESTS_FOR_DJANGO_VERSION = {
25-
# if the second value is False, skip the test, otherwise run it
26-
('func_noerror_protected_meta_access', django_version >= (1, 8)),
27-
}
28-
29-
30-
def module_exists(module_name):
31-
try:
32-
__import__(module_name)
33-
except ImportError:
34-
return False
35-
else:
36-
return True
37-
3810

39-
def tests(input_dir, messages_dir):
40-
callbacks = [cb_test_gen(LintTestUsingFile)]
4111

42-
input_dir = os.path.join(HERE, input_dir)
43-
messages_dir = os.path.join(HERE, messages_dir)
12+
def get_tests():
13+
HERE = os.path.dirname(os.path.abspath(__file__))
14+
input_dir = os.path.join(HERE, 'input')
4415

45-
# first tests which pass for all Django versions
46-
tests = make_tests(input_dir, messages_dir, None, callbacks)
16+
suite = []
17+
for fname in os.listdir(input_dir):
18+
if fname != '__init__.py' and fname.endswith('.py'):
19+
suite.append(test_functional.FunctionalTestFile(input_dir, fname))
20+
return suite
4721

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:
55-
if not version_range:
56-
specific_tests.append(test_name)
57-
filter_rgx = '(%s)' % '|'.join(specific_tests)
5822

59-
tests += make_tests(os.path.join(input_dir, 'versions'), messages_dir, filter_rgx, callbacks)
60-
return tests
23+
TESTS = get_tests()
24+
TESTS_NAMES = [t.base for t in TESTS]
6125

6226

63-
def suite():
64-
test_list = tests('input', 'messages')
65-
66-
if module_exists('rest_framework'):
67-
test_list += tests('external_drf', '')
27+
@pytest.mark.parametrize("test_file", TESTS, ids=TESTS_NAMES)
28+
def test_everything(test_file):
29+
test_functional.test_functional(test_file)
6830

69-
return unittest.TestSuite([unittest.makeSuite(test, suiteClass=unittest.TestSuite)
70-
for test in test_list])
7131

7232
if __name__ == '__main__':
73-
unittest.main(defaultTest='suite')
33+
if '-u' in sys.argv:
34+
UPDATE = True
35+
sys.argv.remove('-u')
36+
pytest.main(sys.argv)

0 commit comments

Comments
 (0)