From 5eb0a61db438eb5c16467932028218259f76d427 Mon Sep 17 00:00:00 2001 From: "Mr. Senko" Date: Tue, 16 Jan 2018 14:39:39 +0200 Subject: [PATCH] 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 https://github.com/landscapeio/pylint-django/issues/107 and https://github.com/landscapeio/pylint-django/issues/97 Obsoletes https://github.com/landscapeio/pylint-django/pull/98 --- test/test_func.py | 77 ++++++++++++----------------------------------- 1 file changed, 20 insertions(+), 57 deletions(-) diff --git a/test/test_func.py b/test/test_func.py index 473ba949..e535fb53 100644 --- a/test/test_func.py +++ b/test/test_func.py @@ -1,73 +1,36 @@ import os import sys -import unittest -from django.conf import settings -from pylint.testutils import make_tests, LintTestUsingFile, cb_test_gen, linter +import pytest +from pylint.testutils import linter +from pylint.test import test_functional from pylint_django.compat import django_version - -settings.configure() - - -HERE = os.path.dirname(os.path.abspath(__file__)) - - linter.load_plugin_modules(['pylint_django']) -# Disable some things on Python2.6, since we use a different pylint version here -# (1.3 on Python2.6, 1.4+ on later versions) -if sys.version_info < (2, 7): - linter.global_set_option('required-attributes', ()) - linter.global_set_option('disable', ('E0012',)) - - -SKIP_TESTS_FOR_DJANGO_VERSION = { - # if the second value is False, skip the test, otherwise run it - ('func_noerror_protected_meta_access', django_version >= (1, 8)), -} - - -def module_exists(module_name): - try: - __import__(module_name) - except ImportError: - return False - else: - return True - -def tests(input_dir, messages_dir): - callbacks = [cb_test_gen(LintTestUsingFile)] - input_dir = os.path.join(HERE, input_dir) - messages_dir = os.path.join(HERE, messages_dir) +def get_tests(): + HERE = os.path.dirname(os.path.abspath(__file__)) + input_dir = os.path.join(HERE, 'input') - # first tests which pass for all Django versions - tests = make_tests(input_dir, messages_dir, None, callbacks) + suite = [] + for fname in os.listdir(input_dir): + if fname != '__init__.py' and fname.endswith('.py'): + suite.append(test_functional.FunctionalTestFile(input_dir, fname)) + return suite - # now skip some tests test for specific versions - for example, - # _meta access should not work for django<1.8 but should run and - # pass for django 1.4 - skip the tests which will be checking - # a piece of functionality in pylint-django that should only - # in higher versions. - specific_tests = [] - for test_name, version_range in SKIP_TESTS_FOR_DJANGO_VERSION: - if not version_range: - specific_tests.append(test_name) - filter_rgx = '(%s)' % '|'.join(specific_tests) - tests += make_tests(os.path.join(input_dir, 'versions'), messages_dir, filter_rgx, callbacks) - return tests +TESTS = get_tests() +TESTS_NAMES = [t.base for t in TESTS] -def suite(): - test_list = tests('input', 'messages') - - if module_exists('rest_framework'): - test_list += tests('external_drf', '') +@pytest.mark.parametrize("test_file", TESTS, ids=TESTS_NAMES) +def test_everything(test_file): + test_functional.test_functional(test_file) - return unittest.TestSuite([unittest.makeSuite(test, suiteClass=unittest.TestSuite) - for test in test_list]) if __name__ == '__main__': - unittest.main(defaultTest='suite') + if '-u' in sys.argv: + UPDATE = True + sys.argv.remove('-u') + pytest.main(sys.argv)