@@ -112,16 +112,17 @@ def foo():
112
112
113
113
# Initialize two workspace folders.
114
114
folder1 = tmpdir .mkdir ("folder1" )
115
- ws1 = Workspace (uris .from_fs_path (str (folder1 )), Mock ())
116
- ws1 ._config = Config (ws1 .root_uri , {}, 0 , {})
117
115
folder2 = tmpdir .mkdir ("folder2" )
118
- ws2 = Workspace (uris .from_fs_path (str (folder2 )), Mock ())
119
- ws2 ._config = Config (ws2 .root_uri , {}, 0 , {})
120
116
121
117
# Create configuration file for workspace folder 1.
122
118
mypy_config = folder1 .join ("mypy.ini" )
123
119
mypy_config .write ("[mypy]\n warn_unreachable = True\n check_untyped_defs = True" )
124
120
121
+ ws1 = Workspace (uris .from_fs_path (str (folder1 )), Mock ())
122
+ ws1 ._config = Config (ws1 .root_uri , {}, 0 , {})
123
+ ws2 = Workspace (uris .from_fs_path (str (folder2 )), Mock ())
124
+ ws2 ._config = Config (ws2 .root_uri , {}, 0 , {})
125
+
125
126
# Initialize settings for both folders.
126
127
plugin .pylsp_settings (ws1 ._config )
127
128
plugin .pylsp_settings (ws2 ._config )
@@ -265,19 +266,51 @@ def foo():
265
266
266
267
config_sub_paths = [".config" ]
267
268
269
+ # Create configuration file for workspace.
270
+ plugin_config = tmpdir .join ("pyproject.toml" )
271
+ plugin_config .write (f"[tool.pylsp-mypy]\n enabled = true\n config_sub_paths = { config_sub_paths } " )
272
+ config_dir = tmpdir .mkdir (".config" )
273
+ mypy_config = config_dir .join ("mypy.ini" )
274
+ mypy_config .write ("[mypy]\n warn_unreachable = True\n check_untyped_defs = True" )
275
+
268
276
# Initialize workspace.
277
+
269
278
ws = Workspace (uris .from_fs_path (str (tmpdir )), Mock ())
270
279
ws ._config = Config (ws .root_uri , {}, 0 , {})
271
280
281
+ # Update settings for workspace.
282
+ plugin .pylsp_settings (ws ._config )
283
+
284
+ # Test document to make sure it uses .config/mypy.ini configuration.
285
+ doc = Document (DOC_URI , ws , DOC_SOURCE )
286
+ diags = plugin .pylsp_lint (ws ._config , ws , doc , is_saved = False )
287
+ assert len (diags ) == 1
288
+ diag = diags [0 ]
289
+ assert diag ["message" ] == DOC_ERR_MSG
290
+
291
+
292
+ def test_config_sub_paths_config_changed (tmpdir , last_diagnostics_monkeypatch ):
293
+ DOC_SOURCE = """
294
+ def foo():
295
+ return
296
+ unreachable = 1
297
+ """
298
+ DOC_ERR_MSG = "Statement is unreachable [unreachable]"
299
+
272
300
# Create configuration file for workspace.
273
- plugin_config = tmpdir .join ("pyproject.toml" )
274
- plugin_config .write (f"[tool.pylsp-mypy]\n enabled = true\n config_sub_paths = { config_sub_paths } " )
275
301
config_dir = tmpdir .mkdir (".config" )
276
302
mypy_config = config_dir .join ("mypy.ini" )
277
303
mypy_config .write ("[mypy]\n warn_unreachable = True\n check_untyped_defs = True" )
278
304
305
+ config_sub_paths = [".config" ]
306
+
307
+ # Initialize workspace.
308
+ ws = Workspace (uris .from_fs_path (str (tmpdir )), Mock ())
309
+ ws ._config = Config (ws .root_uri , {}, 0 , {})
310
+
279
311
# Update settings for workspace.
280
312
plugin .pylsp_settings (ws ._config )
313
+ ws .update_config ({"pylsp" : {"plugins" : {"pylsp_mypy" : {"config_sub_paths" : config_sub_paths }}}})
281
314
282
315
# Test document to make sure it uses .config/mypy.ini configuration.
283
316
doc = Document (DOC_URI , ws , DOC_SOURCE )
0 commit comments