Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions python_files/tests/pytestadapter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,34 @@ def runner_with_cwd_env(
pipe_name = generate_random_pipe_name("pytest-discovery-test")

if "COVERAGE_ENABLED" in env_add and "_TEST_VAR_UNITTEST" not in env_add:
process_args = [
sys.executable,
"-m",
"pytest",
"-p",
"vscode_pytest",
"--cov=.",
"--cov-branch",
"-s",
*args,
]
if "_PYTEST_MANUAL_PLUGIN_LOAD" in env_add:
# Test manual plugin loading scenario for issue #25590
process_args = [
sys.executable,
"-m",
"pytest",
"--disable-plugin-autoload",
"-p",
"pytest_cov.plugin",
"-p",
"vscode_pytest",
"--cov=.",
"--cov-branch",
"-s",
*args,
]
else:
process_args = [
sys.executable,
"-m",
"pytest",
"-p",
"vscode_pytest",
"--cov=.",
"--cov-branch",
"-s",
*args,
]

# Generate pipe name, pipe name specific per OS type.

Expand Down
20 changes: 20 additions & 0 deletions python_files/tests/pytestadapter/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,23 @@ def test_coverage_w_omit_config():
assert results
# assert one file is reported and one file (as specified in pyproject.toml) is omitted
assert len(results) == 1


def test_pytest_cov_manual_plugin_loading():
"""
Test that pytest-cov is detected when loaded manually via -p pytest_cov.plugin.

This test verifies the fix for issue #25590, where pytest-cov detection failed
when using --disable-plugin-autoload with -p pytest_cov.plugin. The plugin is
registered under its module name (pytest_cov.plugin) instead of entry point name
(pytest_cov) in this scenario.
"""
args = ["--collect-only"]
env_add = {"COVERAGE_ENABLED": "True", "_PYTEST_MANUAL_PLUGIN_LOAD": "True"}
cov_folder_path = TEST_DATA_PATH / "coverage_gen"

# Should NOT raise VSCodePytestError about pytest-cov not being installed
actual = runner_with_cwd_env(args, cov_folder_path, env_add)
assert actual is not None
# Verify discovery succeeded (status != "error")
assert actual[0].get("status") != "error"
4 changes: 3 additions & 1 deletion python_files/vscode_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def __init__(self, message):


def pytest_load_initial_conftests(early_config, parser, args): # noqa: ARG001
has_pytest_cov = early_config.pluginmanager.hasplugin("pytest_cov")
has_pytest_cov = early_config.pluginmanager.hasplugin(
"pytest_cov"
) or early_config.pluginmanager.hasplugin("pytest_cov.plugin")
has_cov_arg = any("--cov" in arg for arg in args)
if has_cov_arg and not has_pytest_cov:
raise VSCodePytestError(
Expand Down
Loading