From ba1b909be002df1e9130e61f53c3695e0caa3233 Mon Sep 17 00:00:00 2001 From: eleanorjboyd Date: Thu, 10 Oct 2024 11:46:16 -0700 Subject: [PATCH 1/3] add specific error message for missing pytest-cov --- python_files/vscode_pytest/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/python_files/vscode_pytest/__init__.py b/python_files/vscode_pytest/__init__.py index ca06bf174418..0de983299be4 100644 --- a/python_files/vscode_pytest/__init__.py +++ b/python_files/vscode_pytest/__init__.py @@ -67,6 +67,13 @@ 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_cov_arg = any("--cov" in arg for arg in args) + if has_cov_arg and not has_pytest_cov: + raise VSCodePytestError( + "\n \nERROR: pytest-cov is not installed, please install this before running pytest with coverage as pytest-cov is required. \n" + ) + global TEST_RUN_PIPE TEST_RUN_PIPE = os.getenv("TEST_RUN_PIPE") error_string = ( @@ -117,6 +124,7 @@ def pytest_internalerror(excrepr, excinfo): # noqa: ARG001 excinfo -- the exception information of type ExceptionInfo. """ # call.excinfo.exconly() returns the exception as a string. + print("UGHHHHHH2") ERRORS.append(excinfo.exconly() + "\n Check Python Test Logs for more details.") @@ -131,6 +139,8 @@ def pytest_exception_interact(node, call, report): # call.excinfo is the captured exception of the call, if it raised as type ExceptionInfo. # call.excinfo.exconly() returns the exception as a string. # If it is during discovery, then add the error to error logs. + print("UGHHHHHH23") + if IS_DISCOVERY: if call.excinfo and call.excinfo.typename != "AssertionError": if report.outcome == "skipped" and "SkipTest" in str(call): @@ -935,6 +945,10 @@ def pytest_xdist_auto_num_workers( def pytest_plugin_registered(plugin: object, manager: pytest.PytestPluginManager): + # if manager.has_plugin("pytest_cov"): + # print("has plugin cov pytest") + # else: + # print("does not have plugin cov pytest") plugin_name = "vscode_xdist" if ( # only register the plugin if xdist is enabled: From e32ee907d5fcd254b2c164d377a1dfb356175c9f Mon Sep 17 00:00:00 2001 From: eleanorjboyd Date: Thu, 10 Oct 2024 11:49:33 -0700 Subject: [PATCH 2/3] fix prints --- python_files/vscode_pytest/__init__.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/python_files/vscode_pytest/__init__.py b/python_files/vscode_pytest/__init__.py index 0de983299be4..7ba3bbe7f369 100644 --- a/python_files/vscode_pytest/__init__.py +++ b/python_files/vscode_pytest/__init__.py @@ -124,7 +124,6 @@ def pytest_internalerror(excrepr, excinfo): # noqa: ARG001 excinfo -- the exception information of type ExceptionInfo. """ # call.excinfo.exconly() returns the exception as a string. - print("UGHHHHHH2") ERRORS.append(excinfo.exconly() + "\n Check Python Test Logs for more details.") @@ -139,7 +138,6 @@ def pytest_exception_interact(node, call, report): # call.excinfo is the captured exception of the call, if it raised as type ExceptionInfo. # call.excinfo.exconly() returns the exception as a string. # If it is during discovery, then add the error to error logs. - print("UGHHHHHH23") if IS_DISCOVERY: if call.excinfo and call.excinfo.typename != "AssertionError": @@ -945,10 +943,6 @@ def pytest_xdist_auto_num_workers( def pytest_plugin_registered(plugin: object, manager: pytest.PytestPluginManager): - # if manager.has_plugin("pytest_cov"): - # print("has plugin cov pytest") - # else: - # print("does not have plugin cov pytest") plugin_name = "vscode_xdist" if ( # only register the plugin if xdist is enabled: From 70d19fd680f1857f56feee8a997b918bb8b5cb76 Mon Sep 17 00:00:00 2001 From: eleanorjboyd Date: Thu, 10 Oct 2024 11:50:41 -0700 Subject: [PATCH 3/3] unnecessary indentation --- python_files/vscode_pytest/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python_files/vscode_pytest/__init__.py b/python_files/vscode_pytest/__init__.py index 7ba3bbe7f369..028839b13212 100644 --- a/python_files/vscode_pytest/__init__.py +++ b/python_files/vscode_pytest/__init__.py @@ -138,7 +138,6 @@ def pytest_exception_interact(node, call, report): # call.excinfo is the captured exception of the call, if it raised as type ExceptionInfo. # call.excinfo.exconly() returns the exception as a string. # If it is during discovery, then add the error to error logs. - if IS_DISCOVERY: if call.excinfo and call.excinfo.typename != "AssertionError": if report.outcome == "skipped" and "SkipTest" in str(call):