File tree Expand file tree Collapse file tree 3 files changed +51
-12
lines changed
Expand file tree Collapse file tree 3 files changed +51
-12
lines changed Original file line number Diff line number Diff line change @@ -264,17 +264,34 @@ def runner_with_cwd_env(
264264 pipe_name = generate_random_pipe_name ("pytest-discovery-test" )
265265
266266 if "COVERAGE_ENABLED" in env_add and "_TEST_VAR_UNITTEST" not in env_add :
267- process_args = [
268- sys .executable ,
269- "-m" ,
270- "pytest" ,
271- "-p" ,
272- "vscode_pytest" ,
273- "--cov=." ,
274- "--cov-branch" ,
275- "-s" ,
276- * args ,
277- ]
267+ if "_PYTEST_MANUAL_PLUGIN_LOAD" in env_add :
268+ # Test manual plugin loading scenario for issue #25590
269+ process_args = [
270+ sys .executable ,
271+ "-m" ,
272+ "pytest" ,
273+ "--disable-plugin-autoload" ,
274+ "-p" ,
275+ "pytest_cov.plugin" ,
276+ "-p" ,
277+ "vscode_pytest" ,
278+ "--cov=." ,
279+ "--cov-branch" ,
280+ "-s" ,
281+ * args ,
282+ ]
283+ else :
284+ process_args = [
285+ sys .executable ,
286+ "-m" ,
287+ "pytest" ,
288+ "-p" ,
289+ "vscode_pytest" ,
290+ "--cov=." ,
291+ "--cov-branch" ,
292+ "-s" ,
293+ * args ,
294+ ]
278295
279296 # Generate pipe name, pipe name specific per OS type.
280297
Original file line number Diff line number Diff line change @@ -142,3 +142,23 @@ def test_coverage_w_omit_config():
142142 assert results
143143 # assert one file is reported and one file (as specified in pyproject.toml) is omitted
144144 assert len (results ) == 1
145+
146+
147+ def test_pytest_cov_manual_plugin_loading ():
148+ """
149+ Test that pytest-cov is detected when loaded manually via -p pytest_cov.plugin.
150+
151+ This test verifies the fix for issue #25590, where pytest-cov detection failed
152+ when using --disable-plugin-autoload with -p pytest_cov.plugin. The plugin is
153+ registered under its module name (pytest_cov.plugin) instead of entry point name
154+ (pytest_cov) in this scenario.
155+ """
156+ args = ["--collect-only" ]
157+ env_add = {"COVERAGE_ENABLED" : "True" , "_PYTEST_MANUAL_PLUGIN_LOAD" : "True" }
158+ cov_folder_path = TEST_DATA_PATH / "coverage_gen"
159+
160+ # Should NOT raise VSCodePytestError about pytest-cov not being installed
161+ actual = runner_with_cwd_env (args , cov_folder_path , env_add )
162+ assert actual is not None
163+ # Verify discovery succeeded (status != "error")
164+ assert actual [0 ].get ("status" ) != "error"
Original file line number Diff line number Diff line change @@ -87,7 +87,9 @@ def __init__(self, message):
8787
8888
8989def pytest_load_initial_conftests (early_config , parser , args ): # noqa: ARG001
90- has_pytest_cov = early_config .pluginmanager .hasplugin ("pytest_cov" )
90+ has_pytest_cov = early_config .pluginmanager .hasplugin (
91+ "pytest_cov"
92+ ) or early_config .pluginmanager .hasplugin ("pytest_cov.plugin" )
9193 has_cov_arg = any ("--cov" in arg for arg in args )
9294 if has_cov_arg and not has_pytest_cov :
9395 raise VSCodePytestError (
You can’t perform that action at this time.
0 commit comments