|
| 1 | +## VS Code/Cursor Setup Guide for Hummingbot Testing |
| 2 | + |
| 3 | +This guide outlines how to configure VS Code or Cursor to efficiently run and debug Hummingbot tests |
| 4 | + |
| 5 | +**I. Prerequisites:** |
| 6 | + |
| 7 | +* **Hummingbot Repository:** You have cloned the Hummingbot repository to your local machine. |
| 8 | +* **Conda Environment:** You have created and activated the `hummingbot` Conda environment with all necessary dependencies installed. |
| 9 | + |
| 10 | +**II. Required Files and Configuration:** |
| 11 | + |
| 12 | +Ensure the following files exist in your Hummingbot project directory with the specified content. |
| 13 | + |
| 14 | +**1. `.env` (Project Root Directory):** |
| 15 | + |
| 16 | +``` |
| 17 | +PYTHONPATH=${PYTHONPATH}:${PWD} |
| 18 | +CONDA_ENV=hummingbot |
| 19 | +``` |
| 20 | + |
| 21 | +* **`PYTHONPATH`**: This ensures that Python can find the Hummingbot modules within your project directory. |
| 22 | +* **`CONDA_ENV`**: This variable can be used by other tools or scripts to identify the active Conda environment. |
| 23 | + |
| 24 | +**2. `.vscode/settings.json` (Create this directory and file if it doesn't exist):** |
| 25 | + |
| 26 | +```json |
| 27 | +{ |
| 28 | + "python.testing.pytestEnabled": true, |
| 29 | + "python.testing.pytestArgs": [ |
| 30 | + "test", |
| 31 | + // "-v", // optional: verbose output |
| 32 | + |
| 33 | + // From MakeFile (currently broken tests - KEEP UPDATED) |
| 34 | + "--ignore=test/hummingbot/connector/derivative/dydx_v4_perpetual/", |
| 35 | + "--ignore=test/hummingbot/connector/derivative/injective_v2_perpetual/", |
| 36 | + "--ignore=test/hummingbot/connector/exchange/injective_v2/", |
| 37 | + "--ignore=test/hummingbot/remote_iface/", |
| 38 | + "--ignore=test/connector/utilities/oms_connector/", |
| 39 | + "--ignore=test/hummingbot/strategy/amm_arb/", |
| 40 | + |
| 41 | + // Skip prompt tests that modify conf_client.yml |
| 42 | + "--ignore=test/hummingbot/client/command/test_create_command.py", |
| 43 | + ], |
| 44 | + "python.envFile": "${workspaceFolder}/.env", |
| 45 | + "python.pythonPath": "${config:python.defaultInterpreterPath}" // Ensure correct Python interpreter |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | + |
| 50 | +**3. `.vscode/launch.json` (Create this directory and file if it doesn't exist):** |
| 51 | + |
| 52 | +```json |
| 53 | +{ |
| 54 | + "version": "0.2.0", |
| 55 | + "configurations": [ |
| 56 | + { |
| 57 | + "name": "Python: Hummingbot", |
| 58 | + "type": "debugpy", |
| 59 | + "request": "launch", |
| 60 | + "program": "${workspaceRoot}/bin/hummingbot.py", |
| 61 | + "console": "integratedTerminal" |
| 62 | + } |
| 63 | + ] |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +* This configuration allows you to run and debug the main Hummingbot application directly from VS Code/Cursor. |
| 68 | + |
| 69 | +**III. Setup Steps in VS Code/Cursor:** |
| 70 | + |
| 71 | +1. **Open the Hummingbot Project:** Open the root directory of your cloned Hummingbot repository in VS Code or Cursor. |
| 72 | + |
| 73 | +2. **Select the Python Interpreter:** |
| 74 | + * Open the Command Palette: Press `Ctrl+Shift+P` (Windows/Linux) or `Cmd+Shift+P` (macOS). |
| 75 | + * Type "Python: Select Interpreter" and press Enter. |
| 76 | + * A list of available Python interpreters will appear. **Select the Python interpreter associated with your `hummingbot` Conda environment.** The path should typically include the name of your Conda environment. |
| 77 | + |
| 78 | +3. **Ensure `.env` is Loaded:** VS Code/Cursor should automatically load the `.env` file specified in `settings.json`. You can verify this by checking the Python environment variables within the IDE's terminal or debug configurations. |
| 79 | + |
| 80 | +4. **Fix Test Discovery (Conda Environment Issue):** |
| 81 | + * Open your terminal. |
| 82 | + * Run the following commands to create a symbolic link to work around a known Conda environment detection issue: |
| 83 | + ```bash |
| 84 | + mkdir -p ~/anaconda3/envs/hummingbot/envs |
| 85 | + ln -s ~/anaconda3/envs/hummingbot/ ~/anaconda3/envs/hummingbot/envs/hummingbot |
| 86 | + ``` |
| 87 | + **Note:** Adjust `~/anaconda3/envs/hummingbot` to the actual path of your `hummingbot` Conda environment if it's located elsewhere. |
| 88 | +
|
| 89 | +**IV. Running Tests:** |
| 90 | +
|
| 91 | +1. **Open the Testing View:** In the VS Code/Cursor Activity Bar (usually on the left), click on the **Testing icon** (it often looks like a flask or a beaker). |
| 92 | +
|
| 93 | +2. **Discover Tests:** If the tests are not automatically discovered, you might see a prompt to configure testing. Ensure pytest is selected and the `test` directory is specified as the test source. VS Code/Cursor should then discover the tests based on your `settings.json`. |
| 94 | +
|
| 95 | +3. **Run Tests:** |
| 96 | + * You will see a list of discovered tests in the Testing View, organized by file and test function. |
| 97 | + * **Run All Tests:** Click the "Run All Tests" button (usually a play icon at the top). |
| 98 | + * **Run Specific Tests:** You can run individual test files, test classes, or specific test functions by right-clicking on them in the Testing View and selecting "Run". |
| 99 | +
|
| 100 | +4. **View Test Results:** The Testing View will display the status of each test (passed, failed, skipped). You can click on a failed test to see the error output and navigate to the test code. |
| 101 | +
|
| 102 | +**V. Debugging Tests:** |
| 103 | +
|
| 104 | +1. **Set Breakpoints:** In your test files or the Hummingbot code you want to debug, click in the gutter (the space to the left of the line numbers) to set breakpoints. |
| 105 | +
|
| 106 | +2. **Run Tests in Debug Mode:** |
| 107 | + * In the Testing View, right-click on the test(s) you want to debug and select "Debug". |
| 108 | + * VS Code/Cursor will start the debugger and stop at your breakpoints, allowing you to inspect variables, step through code, and understand the flow of execution. |
| 109 | +
|
| 110 | +**VI. Notes on Ignored Tests:** |
| 111 | +
|
| 112 | +* **Broken Tests (Makefile):** The `--ignore` flags in `settings.json` exclude tests that are currently known to be broken (as indicated in the project's `Makefile`). **It is crucial to regularly review and update this list if the status of these tests changes.** |
| 113 | +* **`test_create_command.py`:** Tests in `test_create_command.py` are ignored because they modify the `conf_client.yml` file. Running these tests locally can potentially interfere with your Hummingbot configuration. If you make changes that could affect these commands, ensure your Pull Request (PR) will pass the automated tests, as they might be run in the CI environment. |
| 114 | + |
| 115 | +By following these steps, you can effectively use VS Code or Cursor to run and debug Hummingbot tests, leveraging the IDE's features for a more integrated and potentially more efficient testing experience, especially when debugging is required. Remember to keep the ignored tests list up-to-date with the `Makefile` to maintain consistency. |
0 commit comments