1818
1919
2020@pytest .fixture
21- def diag_mp (monkeypatch ):
21+ def last_diagnostics_monkeypatch (monkeypatch ):
22+ # gets called before every test altering last_diagnostics in order to reset it
2223 monkeypatch .setattr (plugin , "last_diagnostics" , collections .defaultdict (list ))
2324 return monkeypatch
2425
@@ -45,7 +46,7 @@ def test_settings():
4546 assert settings == {"plugins" : {"pylsp_mypy" : {}}}
4647
4748
48- def test_plugin (workspace , diag_mp ):
49+ def test_plugin (workspace , last_diagnostics_monkeypatch ):
4950 config = FakeConfig ()
5051 doc = Document (DOC_URI , workspace , DOC_TYPE_ERR )
5152 plugin .pylsp_settings (config )
@@ -92,7 +93,7 @@ def test_parse_line_with_context(monkeypatch, word, bounds, workspace):
9293 assert diag ["range" ]["end" ] == {"line" : 278 , "character" : bounds [1 ]}
9394
9495
95- def test_multiple_workspaces (tmpdir , diag_mp ):
96+ def test_multiple_workspaces (tmpdir , last_diagnostics_monkeypatch ):
9697 DOC_SOURCE = """
9798def foo():
9899 return
@@ -137,7 +138,7 @@ def test_apply_overrides():
137138 assert plugin .apply_overrides (["1" ], ["a" , True , "b" ]) == ["a" , "1" , "b" ]
138139
139140
140- def test_option_overrides (tmpdir , diag_mp , workspace ):
141+ def test_option_overrides (tmpdir , last_diagnostics_monkeypatch , workspace ):
141142 import sys
142143 from textwrap import dedent
143144 from stat import S_IRWXU
@@ -158,7 +159,7 @@ def test_option_overrides(tmpdir, diag_mp, workspace):
158159 wrapper .chmod (S_IRWXU )
159160
160161 overrides = ["--python-executable" , wrapper .strpath , True ]
161- diag_mp .setattr (
162+ last_diagnostics_monkeypatch .setattr (
162163 FakeConfig ,
163164 "plugin_settings" ,
164165 lambda _ , p : {"overrides" : overrides } if p == "pylsp_mypy" else {},
@@ -176,9 +177,9 @@ def test_option_overrides(tmpdir, diag_mp, workspace):
176177 assert sentinel .exists ()
177178
178179
179- def test_option_overrides_dmypy (diag_mp , workspace ):
180+ def test_option_overrides_dmypy (last_diagnostics_monkeypatch , workspace ):
180181 overrides = ["--python-executable" , "/tmp/fake" , True ]
181- diag_mp .setattr (
182+ last_diagnostics_monkeypatch .setattr (
182183 FakeConfig ,
183184 "plugin_settings" ,
184185 lambda _ , p : {
@@ -191,7 +192,7 @@ def test_option_overrides_dmypy(diag_mp, workspace):
191192 )
192193
193194 m = Mock (wraps = lambda a , ** _ : Mock (returncode = 0 , ** {"stdout.decode" : lambda : "" }))
194- diag_mp .setattr (plugin .subprocess , "run" , m )
195+ last_diagnostics_monkeypatch .setattr (plugin .subprocess , "run" , m )
195196
196197 plugin .pylsp_lint (
197198 config = FakeConfig (),
0 commit comments