Skip to content

Commit a731230

Browse files
committed
Pylint 2.13+ requires an RC file be adjacest to tests, or falls back on a default which is not packaged. Because pylint-dev#358 is imporant, for now pylint-django will just monkey-patch the lint_module_test module to a local test pylintrc
1 parent 633fed8 commit a731230

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

pylint_django/augmentations/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from pylint.checkers.variables import ScopeConsumer, VariablesChecker
3737
from pylint_plugin_utils import augment_visit, suppress_message
3838

39-
from pylint_django.utils import node_is_subclass
39+
from pylint_django.utils import PY3, node_is_subclass
4040

4141
# Note: it would have been nice to import the Manager object from Django and
4242
# get its attributes that way - and this used to be the method - but unfortunately
@@ -329,7 +329,8 @@ def ignore_import_warnings_for_related_fields(orig_method, self, node):
329329

330330
new_things = {}
331331

332-
for name, stmts in consumer.to_consume.items():
332+
iterat = consumer.to_consume.items if PY3 else consumer.to_consume.iteritems
333+
for name, stmts in iterat():
333334
if isinstance(stmts[0], ImportFrom):
334335
if any(n[0] in ("ForeignKey", "OneToOneField") for n in stmts[0].names):
335336
continue

pylint_django/tests/test_func.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import pickle
44
import sys
5+
from pathlib import Path
56

67
import pylint
78
import pytest
@@ -10,7 +11,7 @@
1011

1112
try:
1213
# pylint 2.5: test_functional has been moved to pylint.testutils
13-
from pylint.testutils import FunctionalTestFile, LintModuleTest
14+
from pylint.testutils import FunctionalTestFile, LintModuleTest, lint_module_test
1415

1516
if "test" not in csv.list_dialects():
1617

@@ -19,6 +20,8 @@ class test_dialect(csv.excel):
1920
lineterminator = "\n"
2021

2122
csv.register_dialect("test", test_dialect)
23+
24+
lint_module_test.PYLINTRC = Path(__file__).parent / "testing_pylintrc"
2225
except (ImportError, AttributeError):
2326
# specify directly the directory containing test_functional.py
2427
test_functional_dir = os.getenv("PYLINT_TEST_FUNCTIONAL_DIR", "")
@@ -50,6 +53,7 @@ class PylintDjangoLintModuleTest(LintModuleTest):
5053
"""
5154

5255
def __init__(self, test_file):
56+
# if hasattr(test_file, 'option_file') and test_file.option_file is None:
5357
super(PylintDjangoLintModuleTest, self).__init__(test_file)
5458
self._linter.load_plugin_modules(["pylint_django"])
5559
self._linter.load_plugin_configuration()
@@ -114,7 +118,7 @@ def test_migrations_plugin(test_file):
114118

115119

116120
@pytest.mark.parametrize("test_file", MIGRATIONS_TESTS[:1], ids=MIGRATIONS_TESTS_NAMES[:1])
117-
def test_linter_should_be_pickleable_with_pylint_djang_plugin_installed(test_file):
121+
def test_linter_should_be_pickleable_with_pylint_django_plugin_installed(test_file):
118122
LintTest = PylintDjangoMigrationsTest(test_file)
119123
LintTest.setUp()
120124

pylint_django/tests/testing_pylintrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# A bare minimum pylintrc used for the functional tests that don't specify
2+
# their own settings.
3+
4+
[MESSAGES CONTROL]
5+
disable=
6+
suppressed-message,
7+
locally-disabled,
8+
useless-suppression,

0 commit comments

Comments
 (0)