summaryrefslogtreecommitdiff
path: root/tests/config
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2022-12-05 16:52:17 -0500
committerGitHub <noreply@github.com>2022-12-05 22:52:17 +0100
commitf860e3fe1c03be81e16732123a1e0cdb247db47f (patch)
tree0dfeaef9382e3f1f5b080570438f250a21abe3dd /tests/config
parentffef6f0c0e0ad1e54ea412f77e38a8628f3d32c8 (diff)
downloadpylint-git-f860e3fe1c03be81e16732123a1e0cdb247db47f.tar.gz
Add flag `--clear-cache-post-run` to support server-like usage (#7802)
Use this flag if you expect the linted files to be altered between runs, for instance, if using pylint in a server-like mode. The flag clear's astroid's in-memory caches.
Diffstat (limited to 'tests/config')
-rw-r--r--tests/config/test_config.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/config/test_config.py b/tests/config/test_config.py
index 12d7a6e60..be28d324b 100644
--- a/tests/config/test_config.py
+++ b/tests/config/test_config.py
@@ -6,12 +6,14 @@ from __future__ import annotations
import os
from pathlib import Path
+from tempfile import TemporaryDirectory
import pytest
from pytest import CaptureFixture
from pylint.interfaces import CONFIDENCE_LEVEL_NAMES
from pylint.lint import Run as LintRun
+from pylint.testutils import create_files
from pylint.testutils._run import _Run as Run
from pylint.testutils.configuration_test import run_using_a_configuration_file
@@ -155,3 +157,19 @@ def test_argument_separator() -> None:
"""
runner = Run(["--", str(EMPTY_MODULE)], exit=False)
assert not runner.linter.stats.by_msg
+
+
+def test_clear_cache_post_run() -> None:
+ modname = "changing.py"
+ with TemporaryDirectory() as tmp_dir:
+ create_files([modname], tmp_dir)
+ module = tmp_dir + os.sep + modname
+ # Run class does not produce the wanted failure
+ # must use LintRun to get pylint.lint.Run
+ run_before_edit = LintRun([module, "--clear-cache-post-run=y"], exit=False)
+ with open(module, mode="a", encoding="utf-8") as f:
+ f.write("undefined\n")
+ run_after_edit = LintRun([module, "--clear-cache-post-run=y"], exit=False)
+
+ assert not run_before_edit.linter.stats.by_msg
+ assert run_after_edit.linter.stats.by_msg