Repository: robotcodedev/robotcode (language: python)

Issue:
[ENHANCEMENT] option to disable the test controller
**Is your enhancement request related to a problem? Please describe.**
i've created a pytest plugin that allows you to run robot tests using pytest, as well as generate robot reports for tests written in python: https://github.com/detachhead/pytest-robotframework

however, both the pytest and robotcode extensions add tests to vscode's tests view, which is confusing because it's difficult to tell which is which:

![image](https://github.com/robocorp/robotframework-lsp/assets/57028336/188ee29d-5726-45c3-8fba-44b453b8215d)

**Describe the solution you'd like**
an option to disable the run buttons so it doesn't duplicate the ones added by pytest

**Describe alternatives you've considered**
i added an option to the robotframework-lsp extension: https://github.com/robocorp/robotframework-lsp/pull/993, however there hasn't been a release for several months, and it looks like robotcode might be more actively maintained.



Discussion / hints:
This sounds like a good idea, but there are a few things to bear in mind.

- Switching the setting on/off should not require a complete reload of VSCode
- RobotCode has Multi Workspace Folder Support, i.e. this setting should work on User/(Remote)/Workspace/Folder level (in one project I want to switch it off and in the other not)
- The View is called "Test Explorer" 
- What possibilities are there to execute and debug test cases with the RobotCode Runner? As far as I can see, your PyTest connection does not support the debugging of Robot Framework files.

What interests me, why should I be able to execute Robot Framework test cases with PyTest?


> * Switching the setting on/off should not require a complete reload of VSCode
> * RobotCode has Multi Workspace Folder Support, i.e. this setting should work on User/(Remote)/Workspace/Folder level (in one project I want to switch it off and in the other not)
> * The View is called "Test Explorer"

i'll try to update my PR to address these points. thanks!

> * What possibilities are there to execute and debug test cases with the RobotCode Runner? As far as I can see, your PyTest connection does not support the debugging of Robot Framework files.

unfortunately that's something i haven't figured out yet. i raised an issue about this  at https://github.com/robocorp/robotframework-lsp/issues/994. i don't fully understand how the debugger stuff works or how much of that is relevant to robotcode too. but i'd be happy to try to help implement this functionality in the future if possible

> What interests me, why should I be able to execute Robot Framework test cases with PyTest?

the main motivation behind my pytest plugin is to generate robotframework reports for tests written in python, since i much prefer python to the robot language.

the reason it also supports running `.robot` tests is because i found that makes it much easier to adopt the plugin in an existing codebase with hundreds of robot tests, where we can gradually convert tests to python and have a single tool to manage all of our tests, regardless of the language they're written in.

Fix patch:
diff --git a/package.json b/package.json
index 2878618d2..9cb9c1868 100644
--- a/package.json
+++ b/package.json
@@ -428,6 +428,12 @@
             "default": true,
             "markdownDescription": "Enable/disable inlay hints for namespaces.",
             "scope": "resource"
+          },
+          "robotcode.testExplorer.enabled": {
+            "type": "boolean",
+            "default": true,
+            "description": "Whether to show robot tests in the test explorer. You may want to disable this if you are using another tool to run robot tests.",
+            "scope": "resource"
           }
         }
       },


Test patch:
diff --git a/vscode-client/testcontrollermanager.ts b/vscode-client/testcontrollermanager.ts
index 68a564839..423f9d37f 100644
--- a/vscode-client/testcontrollermanager.ts
+++ b/vscode-client/testcontrollermanager.ts
@@ -127,6 +127,9 @@ class WorkspaceFolderEntry {
   }
 }
 
+const testExplorerIsEnabled = (workspace: vscode.WorkspaceFolder) =>
+  vscode.workspace.getConfiguration("robotcode.testExplorer", workspace).get<boolean>("enabled");
+
 export class TestControllerManager {
   private _disposables: vscode.Disposable;
   public readonly testController: vscode.TestController;
@@ -194,6 +197,17 @@ export class TestControllerManager {
           (_) => undefined,
         );
       }),
+      vscode.workspace.onDidChangeConfiguration((event) => {
+        for (const ws of vscode.workspace.workspaceFolders ?? []) {
+          if (event.affectsConfiguration("robotcode.testExplorer", ws)) {
+            if (testExplorerIsEnabled(ws)) {
+              this.refresh().catch((_) => undefined);
+            } else {
+              if (ws) this.removeWorkspaceFolderItems(ws);
+            }
+          }
+        }
+      }),
       vscode.workspace.onDidCloseTextDocument((document) => this.refreshDocument(document)),
       vscode.workspace.onDidSaveTextDocument((document) => this.refreshDocument(document)),
       vscode.workspace.onDidOpenTextDocument((document) => this.refreshDocument(document)),
@@ -884,7 +898,7 @@ export class TestControllerManager {
       const addedIds = new Set<string>();
 
       for (const folder of vscode.workspace.workspaceFolders ?? []) {
-        if (token?.isCancellationRequested) return;
+        if (token?.isCancellationRequested || !testExplorerIsEnabled(folder)) return;
 
         if (this.robotTestItems.get(folder) === undefined || !this.robotTestItems.get(folder)?.valid) {
           const items = await this.getTestsFromWorkspaceFolder(folder, token);