@@ -112,16 +112,17 @@ def foo():
112112
113113 # Initialize two workspace folders.
114114 folder1 = tmpdir .mkdir ("folder1" )
115- ws1 = Workspace (uris .from_fs_path (str (folder1 )), Mock ())
116- ws1 ._config = Config (ws1 .root_uri , {}, 0 , {})
117115 folder2 = tmpdir .mkdir ("folder2" )
118- ws2 = Workspace (uris .from_fs_path (str (folder2 )), Mock ())
119- ws2 ._config = Config (ws2 .root_uri , {}, 0 , {})
120116
121117 # Create configuration file for workspace folder 1.
122118 mypy_config = folder1 .join ("mypy.ini" )
123119 mypy_config .write ("[mypy]\n warn_unreachable = True\n check_untyped_defs = True" )
124120
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+
125126 # Initialize settings for both folders.
126127 plugin .pylsp_settings (ws1 ._config )
127128 plugin .pylsp_settings (ws2 ._config )
@@ -265,19 +266,51 @@ def foo():
265266
266267 config_sub_paths = [".config" ]
267268
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+
268276 # Initialize workspace.
277+
269278 ws = Workspace (uris .from_fs_path (str (tmpdir )), Mock ())
270279 ws ._config = Config (ws .root_uri , {}, 0 , {})
271280
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+
272300 # 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 } " )
275301 config_dir = tmpdir .mkdir (".config" )
276302 mypy_config = config_dir .join ("mypy.ini" )
277303 mypy_config .write ("[mypy]\n warn_unreachable = True\n check_untyped_defs = True" )
278304
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+
279311 # Update settings for workspace.
280312 plugin .pylsp_settings (ws ._config )
313+ ws .update_config ({"pylsp" : {"plugins" : {"pylsp_mypy" : {"config_sub_paths" : config_sub_paths }}}})
281314
282315 # Test document to make sure it uses .config/mypy.ini configuration.
283316 doc = Document (DOC_URI , ws , DOC_SOURCE )
0 commit comments