Skip to content

Commit

Permalink
Pylint 2.13+ requires an RC file be adjacest to tests, or falls back …
Browse files Browse the repository at this point in the history
…on a default which is not packaged. Because #358 is imporant, for now pylint-django will just monkey-patch the lint_module_test module to a local test pylintrc
  • Loading branch information
carlio committed Mar 25, 2022
1 parent 633fed8 commit a731230
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 3 additions & 2 deletions pylint_django/augmentations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from pylint.checkers.variables import ScopeConsumer, VariablesChecker
from pylint_plugin_utils import augment_visit, suppress_message

from pylint_django.utils import node_is_subclass
from pylint_django.utils import PY3, node_is_subclass

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

new_things = {}

for name, stmts in consumer.to_consume.items():
iterat = consumer.to_consume.items if PY3 else consumer.to_consume.iteritems
for name, stmts in iterat():
if isinstance(stmts[0], ImportFrom):
if any(n[0] in ("ForeignKey", "OneToOneField") for n in stmts[0].names):
continue
Expand Down
8 changes: 6 additions & 2 deletions pylint_django/tests/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import pickle
import sys
from pathlib import Path

import pylint
import pytest
Expand All @@ -10,7 +11,7 @@

try:
# pylint 2.5: test_functional has been moved to pylint.testutils
from pylint.testutils import FunctionalTestFile, LintModuleTest
from pylint.testutils import FunctionalTestFile, LintModuleTest, lint_module_test

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

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

csv.register_dialect("test", test_dialect)

lint_module_test.PYLINTRC = Path(__file__).parent / "testing_pylintrc"
except (ImportError, AttributeError):
# specify directly the directory containing test_functional.py
test_functional_dir = os.getenv("PYLINT_TEST_FUNCTIONAL_DIR", "")
Expand Down Expand Up @@ -50,6 +53,7 @@ class PylintDjangoLintModuleTest(LintModuleTest):
"""

def __init__(self, test_file):
# if hasattr(test_file, 'option_file') and test_file.option_file is None:
super(PylintDjangoLintModuleTest, self).__init__(test_file)
self._linter.load_plugin_modules(["pylint_django"])
self._linter.load_plugin_configuration()
Expand Down Expand Up @@ -114,7 +118,7 @@ def test_migrations_plugin(test_file):


@pytest.mark.parametrize("test_file", MIGRATIONS_TESTS[:1], ids=MIGRATIONS_TESTS_NAMES[:1])
def test_linter_should_be_pickleable_with_pylint_djang_plugin_installed(test_file):
def test_linter_should_be_pickleable_with_pylint_django_plugin_installed(test_file):
LintTest = PylintDjangoMigrationsTest(test_file)
LintTest.setUp()

Expand Down
8 changes: 8 additions & 0 deletions pylint_django/tests/testing_pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# A bare minimum pylintrc used for the functional tests that don't specify
# their own settings.

[MESSAGES CONTROL]
disable=
suppressed-message,
locally-disabled,
useless-suppression,

0 comments on commit a731230

Please sign in to comment.