Skip to content

Commit 54aeecd

Browse files
committed
fix tests; avoid skipped file exploration
1 parent b29b3b6 commit 54aeecd

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

pylint/lint/pylinter.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -615,39 +615,31 @@ def initialize(self) -> None:
615615
if not msg.may_be_emitted(self.config.py_version):
616616
self._msgs_state[msg.msgid] = False
617617

618-
def _discover_files(
619-
self, files_or_modules: Sequence[str], all_files: bool = False
620-
) -> Iterator[str]:
618+
def _discover_files(self, files_or_modules: Sequence[str]) -> Iterator[str]:
621619
"""Discover python modules and packages in sub-directory.
622620
623-
:param Sequence[str] files_or_modules: list of directories to explore
624-
:param str all_files: whether to return _all_ files, entering modules
625-
and not considering ignored paths
626621
Returns iterator of paths to discovered modules and packages.
627622
"""
628623
for something in files_or_modules:
629-
if os.path.isdir(something):
630-
if not all_files and not os.path.isfile(
631-
os.path.join(something, "__init__.py")
632-
):
633-
continue
624+
if os.path.isdir(something) and not os.path.isfile(
625+
os.path.join(something, "__init__.py")
626+
):
634627
skip_subtrees: list[str] = []
635628
for root, _, files in os.walk(something):
636629
if any(root.startswith(s) for s in skip_subtrees):
637630
# Skip subtree of already discovered package.
638631
continue
639632

640-
if not all_files and _is_ignored_file(
633+
if _is_ignored_file(
641634
root,
642635
self.config.ignore,
643636
self.config.ignore_patterns,
644637
self.config.ignore_paths,
645638
):
646-
self.skipped_paths.add(root)
647639
skip_subtrees.append(root)
648640
continue
649641

650-
if not all_files and "__init__.py" in files:
642+
if "__init__.py" in files:
651643
skip_subtrees.append(root)
652644
yield root
653645
else:
@@ -1156,11 +1148,8 @@ def _report_evaluation(self, verbose: bool = False) -> int | None:
11561148

11571149
if verbose:
11581150
checked_files_count = self.stats.node_count["module"]
1159-
skipped_files = list(
1160-
self._discover_files(list(self.skipped_paths), all_files=True)
1161-
)
1162-
skipped_files_count = len(skipped_files)
1163-
msg += f"\nChecked {checked_files_count} files, skipped {skipped_files_count} files"
1151+
skipped_paths_count = len(self.skipped_paths)
1152+
msg += f"\nChecked {checked_files_count} files, skipped {skipped_paths_count} files/modules"
11641153

11651154
if self.config.score:
11661155
sect = report_nodes.EvaluationSection(msg)

tests/lint/unittest_expand_modules.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def test__is_in_ignore_list_re_match() -> None:
4040
"isarg": True,
4141
"name": "lint.unittest_expand_modules",
4242
"path": EXPAND_MODULES,
43+
"isignored": False,
4344
}
4445

4546
this_file_relative_to_parent = {
@@ -48,6 +49,7 @@ def test__is_in_ignore_list_re_match() -> None:
4849
"isarg": True,
4950
"name": "lint.unittest_expand_modules",
5051
"path": EXPAND_MODULES_BASE,
52+
"isignored": False,
5153
}
5254

5355
this_file_from_init = {
@@ -56,6 +58,7 @@ def test__is_in_ignore_list_re_match() -> None:
5658
"isarg": False,
5759
"name": "lint.unittest_expand_modules",
5860
"path": EXPAND_MODULES,
61+
"isignored": False,
5962
}
6063

6164
this_file_from_init_deduplicated = {
@@ -64,6 +67,7 @@ def test__is_in_ignore_list_re_match() -> None:
6467
"isarg": True,
6568
"name": "lint.unittest_expand_modules",
6669
"path": EXPAND_MODULES,
70+
"isignored": False,
6771
}
6872

6973
unittest_lint = {
@@ -72,6 +76,7 @@ def test__is_in_ignore_list_re_match() -> None:
7276
"isarg": False,
7377
"name": "lint.unittest_lint",
7478
"path": str(TEST_DIRECTORY / "lint/unittest_lint.py"),
79+
"isignored": False,
7580
}
7681

7782
test_utils = {
@@ -80,6 +85,7 @@ def test__is_in_ignore_list_re_match() -> None:
8085
"isarg": False,
8186
"name": "lint.test_utils",
8287
"path": str(TEST_DIRECTORY / "lint/test_utils.py"),
88+
"isignored": False,
8389
}
8490

8591
test_run_pylint = {
@@ -88,6 +94,7 @@ def test__is_in_ignore_list_re_match() -> None:
8894
"isarg": False,
8995
"name": "lint.test_run_pylint",
9096
"path": str(TEST_DIRECTORY / "lint/test_run_pylint.py"),
97+
"isignored": False,
9198
}
9299

93100
test_pylinter = {
@@ -96,6 +103,7 @@ def test__is_in_ignore_list_re_match() -> None:
96103
"isarg": False,
97104
"name": "lint.test_pylinter",
98105
"path": str(TEST_DIRECTORY / "lint/test_pylinter.py"),
106+
"isignored": False,
99107
}
100108

101109
test_caching = {
@@ -104,6 +112,7 @@ def test__is_in_ignore_list_re_match() -> None:
104112
"isarg": False,
105113
"name": "lint.test_caching",
106114
"path": str(TEST_DIRECTORY / "lint/test_caching.py"),
115+
"isignored": False,
107116
}
108117

109118
init_of_package = {
@@ -112,6 +121,7 @@ def test__is_in_ignore_list_re_match() -> None:
112121
"isarg": True,
113122
"name": "lint",
114123
"path": INIT_PATH,
124+
"isignored": False,
115125
}
116126

117127
# A directory that is not a python package.
@@ -123,13 +133,15 @@ def test__is_in_ignore_list_re_match() -> None:
123133
"isarg": False,
124134
"basepath": str(REPORTERS_PATH / "__init__.py"),
125135
"basename": "reporters",
136+
"isignored": False,
126137
},
127138
str(REPORTERS_PATH / "unittest_reporting.py"): {
128139
"path": str(REPORTERS_PATH / "unittest_reporting.py"),
129140
"name": "reporters.unittest_reporting",
130141
"isarg": False,
131142
"basepath": str(REPORTERS_PATH / "__init__.py"),
132143
"basename": "reporters",
144+
"isignored": False,
133145
},
134146
}
135147

@@ -304,5 +316,5 @@ def test_expand_modules_with_ignore(
304316
ignore_list_re,
305317
self.linter.config.ignore_paths,
306318
)
307-
assert modules == expected
319+
assert {k: v for k, v in modules.items() if not v["isignored"]} == expected
308320
assert not errors

tests/test_self.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def test_output_with_verbose(self) -> None:
257257
out=out,
258258
code=4,
259259
)
260-
assert "Checked 1 files, skipped 1 files" in out.getvalue().strip()
260+
assert "Checked 1 files, skipped 1 files/modules" in out.getvalue().strip()
261261

262262
def test_no_out_encoding(self) -> None:
263263
"""Test redirection of stdout with non ascii characters."""

0 commit comments

Comments
 (0)