|
1 | 1 |
|
2 | 2 | import os
|
3 | 3 | 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 |
7 | 7 | from pylint_django.compat import django_version
|
8 | 8 |
|
9 |
| - |
10 |
| -settings.configure() |
11 |
| - |
12 |
| - |
13 |
| -HERE = os.path.dirname(os.path.abspath(__file__)) |
14 |
| - |
15 |
| - |
16 | 9 | 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 |
| - |
38 | 10 |
|
39 |
| -def tests(input_dir, messages_dir): |
40 |
| - callbacks = [cb_test_gen(LintTestUsingFile)] |
41 | 11 |
|
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') |
44 | 15 |
|
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 |
47 | 21 |
|
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) |
58 | 22 |
|
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] |
61 | 25 |
|
62 | 26 |
|
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) |
68 | 30 |
|
69 |
| - return unittest.TestSuite([unittest.makeSuite(test, suiteClass=unittest.TestSuite) |
70 |
| - for test in test_list]) |
71 | 31 |
|
72 | 32 | 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