6
6
7
7
import os
8
8
import os .path
9
+ from io import StringIO
9
10
from pathlib import Path
10
11
11
12
import pytest
12
13
from pytest import CaptureFixture
13
14
14
15
from pylint .lint import Run as LintRun
15
16
from pylint .testutils ._run import _Run as Run
16
- from pylint .testutils .utils import _test_cwd
17
+ from pylint .testutils .utils import _patch_streams , _test_cwd
17
18
18
19
19
20
def test_fall_back_on_base_config (tmp_path : Path ) -> None :
@@ -65,7 +66,7 @@ def _create_subconfig_test_fs(tmp_path: Path) -> tuple[Path, ...]:
65
66
66
67
@pytest .mark .parametrize (
67
68
"local_config_args" ,
68
- [["--use-local-configs=y" ]],
69
+ [["--use-local-configs=y" ], [ "--use-local-configs=y" , "--jobs=2" ] ],
69
70
)
70
71
# check modules and use of configuration files from top-level package or subpackage
71
72
@pytest .mark .parametrize ("test_file_index" , [0 , 1 , 2 ])
@@ -75,7 +76,6 @@ def _create_subconfig_test_fs(tmp_path: Path) -> tuple[Path, ...]:
75
76
)
76
77
def test_subconfig_vs_root_config (
77
78
_create_subconfig_test_fs : tuple [Path , ...],
78
- capsys : CaptureFixture ,
79
79
test_file_index : int ,
80
80
local_config_args : list [str ],
81
81
start_dir_modificator : str ,
@@ -87,46 +87,63 @@ def test_subconfig_vs_root_config(
87
87
test_file = tmp_files [test_file_index ]
88
88
start_dir = (level1_dir / start_dir_modificator ).resolve ()
89
89
90
- output = [f"{ start_dir = } \n { test_file = } \n " ]
90
+ output = [f"{ start_dir = } " ]
91
91
with _test_cwd (start_dir ):
92
92
for _ in range (2 ):
93
- # _Run adds --rcfile, which overrides config from cwd, so we need original Run here
94
- LintRun ([* local_config_args , str (test_file )], exit = False )
95
- output .append (capsys .readouterr ().out .replace ("\\ n" , "\n " ))
93
+ out = StringIO ()
94
+ with _patch_streams (out ):
95
+ # _Run adds --rcfile, which overrides config from cwd, so we need original Run here
96
+ LintRun ([* local_config_args , str (test_file )], exit = False )
97
+ current_file_output = f"{ test_file = } \n " + out .getvalue ()
98
+ output .append (current_file_output )
96
99
test_file = test_file .parent
97
100
98
101
expected_note = "LEVEL1"
99
102
if test_file_index == 1 :
100
103
expected_note = "LEVEL2"
101
- assert_message = f"Wrong note after checking FILE. Readable debug output:\n { output [0 ]} \n { output [1 ]} "
104
+ assert_message = (
105
+ "local pylintrc was not used for checking FILE. "
106
+ f"Readable debug output:\n { output [0 ]} \n { output [1 ]} "
107
+ )
102
108
assert expected_note in output [1 ], assert_message
103
- assert_message = f"Wrong note after checking DIRECTORY. Readable debug output:\n { output [0 ]} \n { output [2 ]} "
109
+ assert_message = (
110
+ "local pylintrc was not used for checking DIRECTORY. "
111
+ f"Readable debug output:\n { output [0 ]} \n { output [2 ]} "
112
+ )
104
113
assert expected_note in output [2 ], assert_message
105
114
106
115
if test_file_index == 0 :
107
116
# 'pylint level1_dir/' should use config from subpackage when checking level1_dir/sub/b.py
108
- assert_message = f"Wrong note after checking DIRECTORY. Readable debug output:\n { output [0 ]} \n { output [2 ]} "
117
+ assert_message = (
118
+ "local pylintrc was not used for checking DIRECTORY. "
119
+ f"Readable debug output:\n { output [0 ]} \n { output [2 ]} "
120
+ )
109
121
assert "LEVEL2" in output [2 ], assert_message
110
122
if test_file_index == 1 :
111
123
# 'pylint level1_dir/sub/b.py' and 'pylint level1_dir/sub/' should use
112
124
# level1_dir/sub/pylintrc, not level1_dir/pylintrc
113
- assert_message = f"Wrong note after checking FILE. Readable debug output:\n { output [0 ]} \n { output [1 ]} "
125
+ assert_message = (
126
+ "parent config was used instead of local for checking FILE. "
127
+ f"Readable debug output:\n { output [0 ]} \n { output [1 ]} "
128
+ )
114
129
assert "LEVEL1" not in output [1 ], assert_message
115
- assert_message = f"Wrong note after checking DIRECTORY. Readable debug output:\n { output [0 ]} \n { output [2 ]} "
130
+ assert_message = (
131
+ "parent config was used instead of local for checking DIRECTORY. "
132
+ f"Readable debug output:\n { output [0 ]} \n { output [2 ]} "
133
+ )
116
134
assert "LEVEL1" not in output [2 ], assert_message
117
135
118
136
119
137
@pytest .mark .parametrize (
120
138
"local_config_args" ,
121
- [["--use-local-configs=y" ]],
139
+ [["--use-local-configs=y" ], [ "--use-local-configs=y" , "--jobs=2" ] ],
122
140
)
123
141
# check cases when test_file without local config belongs to cwd subtree or not
124
142
@pytest .mark .parametrize (
125
143
"start_dir_modificator" , ["." , ".." , "../level1_dir_without_config" ]
126
144
)
127
145
def test_missing_local_config (
128
146
_create_subconfig_test_fs : tuple [Path , ...],
129
- capsys : CaptureFixture ,
130
147
local_config_args : list [str ],
131
148
start_dir_modificator : str ,
132
149
) -> None :
@@ -138,23 +155,31 @@ def test_missing_local_config(
138
155
test_file = tmp_files [3 ]
139
156
start_dir = (level1_dir / start_dir_modificator ).resolve ()
140
157
141
- output = [f"{ start_dir = } \n { test_file = } \n " ]
158
+ output = [f"{ start_dir = } " ]
142
159
with _test_cwd (start_dir ):
143
160
for _ in range (2 ):
144
- # _Run adds --rcfile, which overrides config from cwd, so we need original Run here
145
- LintRun ([* local_config_args , str (test_file )], exit = False )
146
- output .append (capsys .readouterr ().out .replace ("\\ n" , "\n " ))
147
-
161
+ out = StringIO ()
162
+ with _patch_streams (out ):
163
+ # _Run adds --rcfile, which overrides config from cwd, so we need original Run here
164
+ LintRun ([* local_config_args , str (test_file )], exit = False )
165
+ current_file_output = f"{ test_file = } \n " + out .getvalue ()
166
+ output .append (current_file_output )
148
167
test_file = test_file .parent
149
168
150
169
# from default config
151
170
expected_note = "TODO"
152
171
if start_dir_modificator == "." :
153
172
# from config in level1_dir
154
173
expected_note = "LEVEL1"
155
- assert_message = f"Wrong note after checking FILE. Readable debug output:\n { output [0 ]} \n { output [1 ]} "
174
+ assert_message = (
175
+ "wrong config was used for checking FILE. "
176
+ f"Readable debug output:\n { output [0 ]} \n { output [1 ]} "
177
+ )
156
178
assert expected_note in output [1 ], assert_message
157
- assert_message = f"Wrong note after checking DIRECTORY. Readable debug output:\n { output [0 ]} \n { output [2 ]} "
179
+ assert_message = (
180
+ "wrong config was used for checking DIRECTORY. "
181
+ f"Readable debug output:\n { output [0 ]} \n { output [2 ]} "
182
+ )
158
183
assert expected_note in output [2 ], assert_message
159
184
160
185
0 commit comments