From 06859879f3da4cdb3ca9255635ab6429bccad1e7 Mon Sep 17 00:00:00 2001 From: Courtney Webster <60238438+cwebster-99@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:04:32 +0000 Subject: [PATCH 01/11] Adding django test docs --- docs/python/testing.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/python/testing.md b/docs/python/testing.md index a75db9a534..750663deb3 100644 --- a/docs/python/testing.md +++ b/docs/python/testing.md @@ -163,6 +163,25 @@ If discovery fails (for example, the test framework isn't installed or you have ![Discovery failure error messaged displayed in the Test Explorer](images/testing/test-discovery-error.png) +### Django unittests + +The Python extension also offers support for running Django unittests! However, if you are writing tests for your Django application, there are a few additional steps needed in order to have your tests discovered. + +First, ensure you have correctly set `"python.testing.unittestEnabled": true,` in your `settings.json` file. Follow the steps below to add `MANAGE_PY_PATH` as an environment variable: + +- Create a file named `.env` at the root of your project. +- Add `MANAGE_PY_PATH='path-string-to-manange.py-path'` to the `.env` file, replacing `path-string-to-manange.py-path` with the path to your application's `manage.py` file (Note: you can copy the path by right clicking on the file and selecting **Copy Path**). +- Add the following to your `settings.json` file `"python.envFile": "${workspaceFolder}/.env”` to incorporate this file in your environment (edit path as necessary if `.env` is not at root). + +Navigate to the Testing Panel, and refresh the tree-view to see your Django tests populate! + +In the case your tests are not discovered, try the following troubleshooting steps: + +- Add `"python.testing.unittestArgs": []` in `settings.json` +- Look at the Python Output Panel for any error messages that may have triggered. +- Try running commands in the Command Line, then transfer the same command to how it is represented in VS Code. For example, you may run `python manage.py test --arg` in the Command Line which is represented by setting `MANAGE_PY_PATH='./manage.py'` and `"python.testing.unittestArgs": [--arg]` in VS Code. Check the output as it should print the commands that are actually ran. +- Attempt using the absolute path for `manage.py`, if you initially tried using the relative path. + Once VS Code recognizes tests, it provides several ways to run those tests as described in [Run tests](#run-tests). ## Run tests From 5c02163ce2ce3a843ebda32854cac61fba5d36ce Mon Sep 17 00:00:00 2001 From: Courtney Webster <60238438+cwebster-99@users.noreply.github.com> Date: Tue, 20 Aug 2024 13:14:11 -0500 Subject: [PATCH 02/11] Apply suggestions from code review --- docs/python/testing.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/python/testing.md b/docs/python/testing.md index 750663deb3..eb8ada2328 100644 --- a/docs/python/testing.md +++ b/docs/python/testing.md @@ -167,17 +167,16 @@ If discovery fails (for example, the test framework isn't installed or you have The Python extension also offers support for running Django unittests! However, if you are writing tests for your Django application, there are a few additional steps needed in order to have your tests discovered. -First, ensure you have correctly set `"python.testing.unittestEnabled": true,` in your `settings.json` file. Follow the steps below to add `MANAGE_PY_PATH` as an environment variable: +First, ensure you have correctly set `"python.testing.unittestEnabled": true,` in your `settings.json` file, then follow the steps below to add `MANAGE_PY_PATH` as an environment variable: - Create a file named `.env` at the root of your project. - Add `MANAGE_PY_PATH='path-string-to-manange.py-path'` to the `.env` file, replacing `path-string-to-manange.py-path` with the path to your application's `manage.py` file (Note: you can copy the path by right clicking on the file and selecting **Copy Path**). - Add the following to your `settings.json` file `"python.envFile": "${workspaceFolder}/.env”` to incorporate this file in your environment (edit path as necessary if `.env` is not at root). - +- Add Django args to `"python.testing.unittestArgs": []` in `settings.json` as needed, and remove any arguments that are not compatible with Django. Navigate to the Testing Panel, and refresh the tree-view to see your Django tests populate! In the case your tests are not discovered, try the following troubleshooting steps: -- Add `"python.testing.unittestArgs": []` in `settings.json` - Look at the Python Output Panel for any error messages that may have triggered. - Try running commands in the Command Line, then transfer the same command to how it is represented in VS Code. For example, you may run `python manage.py test --arg` in the Command Line which is represented by setting `MANAGE_PY_PATH='./manage.py'` and `"python.testing.unittestArgs": [--arg]` in VS Code. Check the output as it should print the commands that are actually ran. - Attempt using the absolute path for `manage.py`, if you initially tried using the relative path. From 802ce2fe43b3cdd5f1bcbea31732ea12cbd3c4f5 Mon Sep 17 00:00:00 2001 From: Courtney Webster <60238438+cwebster-99@users.noreply.github.com> Date: Tue, 20 Aug 2024 13:14:42 -0500 Subject: [PATCH 03/11] Update docs/python/testing.md --- docs/python/testing.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/python/testing.md b/docs/python/testing.md index eb8ada2328..d54d5494bb 100644 --- a/docs/python/testing.md +++ b/docs/python/testing.md @@ -173,6 +173,7 @@ First, ensure you have correctly set `"python.testing.unittestEnabled": true,` i - Add `MANAGE_PY_PATH='path-string-to-manange.py-path'` to the `.env` file, replacing `path-string-to-manange.py-path` with the path to your application's `manage.py` file (Note: you can copy the path by right clicking on the file and selecting **Copy Path**). - Add the following to your `settings.json` file `"python.envFile": "${workspaceFolder}/.env”` to incorporate this file in your environment (edit path as necessary if `.env` is not at root). - Add Django args to `"python.testing.unittestArgs": []` in `settings.json` as needed, and remove any arguments that are not compatible with Django. + Navigate to the Testing Panel, and refresh the tree-view to see your Django tests populate! In the case your tests are not discovered, try the following troubleshooting steps: From bde8f76f169a644b6cadeefcc6e2cd46e8b2bf1d Mon Sep 17 00:00:00 2001 From: Courtney Webster <60238438+cwebster-99@users.noreply.github.com> Date: Tue, 20 Aug 2024 17:28:23 -0500 Subject: [PATCH 04/11] Apply suggestions from code review Co-authored-by: Luciana Abud <45497113+luabud@users.noreply.github.com> --- docs/python/testing.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/python/testing.md b/docs/python/testing.md index d54d5494bb..c7facf184e 100644 --- a/docs/python/testing.md +++ b/docs/python/testing.md @@ -165,16 +165,16 @@ If discovery fails (for example, the test framework isn't installed or you have ### Django unittests -The Python extension also offers support for running Django unittests! However, if you are writing tests for your Django application, there are a few additional steps needed in order to have your tests discovered. +The Python extension also offers support for running Django unittests! You get your Django tests discovered with only a few additional set up steps. First, ensure you have correctly set `"python.testing.unittestEnabled": true,` in your `settings.json` file, then follow the steps below to add `MANAGE_PY_PATH` as an environment variable: - Create a file named `.env` at the root of your project. -- Add `MANAGE_PY_PATH='path-string-to-manange.py-path'` to the `.env` file, replacing `path-string-to-manange.py-path` with the path to your application's `manage.py` file (Note: you can copy the path by right clicking on the file and selecting **Copy Path**). -- Add the following to your `settings.json` file `"python.envFile": "${workspaceFolder}/.env”` to incorporate this file in your environment (edit path as necessary if `.env` is not at root). +- Add `MANAGE_PY_PATH='path-string-to-manange.py-path'` to the `.env` file, replacing `path-string-to-manange.py-path` with the path to your application's `manage.py` file (Note: you can copy the path by right clicking on the file in the File Explorer and selecting **Copy Path**). +- Add `"python.envFile": "${workspaceFolder}/.env”` to your `settings.json` file, so the Python extension can load the environment variables in this file when running and discovering tests (edit path as necessary if `.env` is not at root). - Add Django args to `"python.testing.unittestArgs": []` in `settings.json` as needed, and remove any arguments that are not compatible with Django. -Navigate to the Testing Panel, and refresh the tree-view to see your Django tests populate! +Navigate to the Testing Panel, and refresh the tree-view to have your Django tests displayed! In the case your tests are not discovered, try the following troubleshooting steps: From fd088de1290916e3ca903ef21d584d87befc1bf0 Mon Sep 17 00:00:00 2001 From: Luciana Abud <45497113+luabud@users.noreply.github.com> Date: Mon, 26 Aug 2024 18:15:40 -0700 Subject: [PATCH 05/11] Small tweaks --- docs/python/testing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/python/testing.md b/docs/python/testing.md index c7facf184e..418af43898 100644 --- a/docs/python/testing.md +++ b/docs/python/testing.md @@ -171,14 +171,14 @@ First, ensure you have correctly set `"python.testing.unittestEnabled": true,` i - Create a file named `.env` at the root of your project. - Add `MANAGE_PY_PATH='path-string-to-manange.py-path'` to the `.env` file, replacing `path-string-to-manange.py-path` with the path to your application's `manage.py` file (Note: you can copy the path by right clicking on the file in the File Explorer and selecting **Copy Path**). -- Add `"python.envFile": "${workspaceFolder}/.env”` to your `settings.json` file, so the Python extension can load the environment variables in this file when running and discovering tests (edit path as necessary if `.env` is not at root). +- Add `"python.envFile": "${workspaceFolder}/.env"` to your `settings.json` file, so the Python extension can load the environment variables in this file when running and discovering tests (edit path as necessary if `.env` is not at root). - Add Django args to `"python.testing.unittestArgs": []` in `settings.json` as needed, and remove any arguments that are not compatible with Django. Navigate to the Testing Panel, and refresh the tree-view to have your Django tests displayed! In the case your tests are not discovered, try the following troubleshooting steps: -- Look at the Python Output Panel for any error messages that may have triggered. +- Search for error messages in the **Python** output panel. - Try running commands in the Command Line, then transfer the same command to how it is represented in VS Code. For example, you may run `python manage.py test --arg` in the Command Line which is represented by setting `MANAGE_PY_PATH='./manage.py'` and `"python.testing.unittestArgs": [--arg]` in VS Code. Check the output as it should print the commands that are actually ran. - Attempt using the absolute path for `manage.py`, if you initially tried using the relative path. From 8b106736d8a0a7b53dbf1754a2a0b6b5b50229fd Mon Sep 17 00:00:00 2001 From: Luciana Abud <45497113+luabud@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:42:05 -0700 Subject: [PATCH 06/11] Apply suggestions from code review Co-authored-by: Nick Trogh <1908215+ntrogh@users.noreply.github.com> --- docs/python/testing.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/python/testing.md b/docs/python/testing.md index 418af43898..0c2c1ce252 100644 --- a/docs/python/testing.md +++ b/docs/python/testing.md @@ -163,23 +163,24 @@ If discovery fails (for example, the test framework isn't installed or you have ![Discovery failure error messaged displayed in the Test Explorer](images/testing/test-discovery-error.png) -### Django unittests +### Django unit tests -The Python extension also offers support for running Django unittests! You get your Django tests discovered with only a few additional set up steps. +The Python extension also offers support for running Django unit tests! You get your Django tests discovered with only a few additional set up steps. First, ensure you have correctly set `"python.testing.unittestEnabled": true,` in your `settings.json` file, then follow the steps below to add `MANAGE_PY_PATH` as an environment variable: - Create a file named `.env` at the root of your project. -- Add `MANAGE_PY_PATH='path-string-to-manange.py-path'` to the `.env` file, replacing `path-string-to-manange.py-path` with the path to your application's `manage.py` file (Note: you can copy the path by right clicking on the file in the File Explorer and selecting **Copy Path**). +- Add `MANAGE_PY_PATH='path-string-to-manage.py-path'` to the `.env` file, replacing `path-string-to-manage.py-path` with the path to your application's `manage.py` file. + > **Tip**: you can copy the path by right clicking on the file in the Explorer view and selecting **Copy Path**. - Add `"python.envFile": "${workspaceFolder}/.env"` to your `settings.json` file, so the Python extension can load the environment variables in this file when running and discovering tests (edit path as necessary if `.env` is not at root). - Add Django args to `"python.testing.unittestArgs": []` in `settings.json` as needed, and remove any arguments that are not compatible with Django. -Navigate to the Testing Panel, and refresh the tree-view to have your Django tests displayed! +Navigate to the Testing view, and select the **Refresh Tests** button to have your Django tests displayed! -In the case your tests are not discovered, try the following troubleshooting steps: +If your tests are still not showing in the Testing view, try the following troubleshooting steps: - Search for error messages in the **Python** output panel. -- Try running commands in the Command Line, then transfer the same command to how it is represented in VS Code. For example, you may run `python manage.py test --arg` in the Command Line which is represented by setting `MANAGE_PY_PATH='./manage.py'` and `"python.testing.unittestArgs": [--arg]` in VS Code. Check the output as it should print the commands that are actually ran. +- Try running commands in the command line, then transfer the same command to how it is represented in VS Code. For example, you may run `python manage.py test --arg` in the command line, which is represented by setting `MANAGE_PY_PATH='./manage.py'` and `"python.testing.unittestArgs": [--arg]` in VS Code. Check the output as it should print the commands that are actually ran. - Attempt using the absolute path for `manage.py`, if you initially tried using the relative path. Once VS Code recognizes tests, it provides several ways to run those tests as described in [Run tests](#run-tests). From 896e760a7b85f85a438c85a9737c350b34a6cf1e Mon Sep 17 00:00:00 2001 From: Luciana Abud <45497113+luabud@users.noreply.github.com> Date: Wed, 28 Aug 2024 00:16:25 +0000 Subject: [PATCH 07/11] Move section and enumerate set up steps --- docs/python/testing.md | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/docs/python/testing.md b/docs/python/testing.md index 0c2c1ce252..27b2db7172 100644 --- a/docs/python/testing.md +++ b/docs/python/testing.md @@ -163,26 +163,6 @@ If discovery fails (for example, the test framework isn't installed or you have ![Discovery failure error messaged displayed in the Test Explorer](images/testing/test-discovery-error.png) -### Django unit tests - -The Python extension also offers support for running Django unit tests! You get your Django tests discovered with only a few additional set up steps. - -First, ensure you have correctly set `"python.testing.unittestEnabled": true,` in your `settings.json` file, then follow the steps below to add `MANAGE_PY_PATH` as an environment variable: - -- Create a file named `.env` at the root of your project. -- Add `MANAGE_PY_PATH='path-string-to-manage.py-path'` to the `.env` file, replacing `path-string-to-manage.py-path` with the path to your application's `manage.py` file. - > **Tip**: you can copy the path by right clicking on the file in the Explorer view and selecting **Copy Path**. -- Add `"python.envFile": "${workspaceFolder}/.env"` to your `settings.json` file, so the Python extension can load the environment variables in this file when running and discovering tests (edit path as necessary if `.env` is not at root). -- Add Django args to `"python.testing.unittestArgs": []` in `settings.json` as needed, and remove any arguments that are not compatible with Django. - -Navigate to the Testing view, and select the **Refresh Tests** button to have your Django tests displayed! - -If your tests are still not showing in the Testing view, try the following troubleshooting steps: - -- Search for error messages in the **Python** output panel. -- Try running commands in the command line, then transfer the same command to how it is represented in VS Code. For example, you may run `python manage.py test --arg` in the command line, which is represented by setting `MANAGE_PY_PATH='./manage.py'` and `"python.testing.unittestArgs": [--arg]` in VS Code. Check the output as it should print the commands that are actually ran. -- Attempt using the absolute path for `manage.py`, if you initially tried using the relative path. - Once VS Code recognizes tests, it provides several ways to run those tests as described in [Run tests](#run-tests). ## Run tests @@ -333,6 +313,28 @@ Below are all the supported commands for testing with the Python extension in VS | **Testing: Focus on Test Explorer View** | Open the Test Explorer view. Similar to **Testing: Focus on Python View** on versions prior to 2021.9. | **Test: Stop Refreshing Tests** | Cancel test discovery. | +## Django unit tests + +The Python extension also offers support for discovering and running Django unit tests! You can get your Django tests discovered with only a few additional set up steps. + + +1. Set `"python.testing.unittestEnabled": true,` in your `settings.json`. +2. Add `MANAGE_PY_PATH` as an environment variable: + 1. Create a file named `.env` at the root of your project. + 2. Add `MANAGE_PY_PATH='path-string-to-manage.py-path'` to the `.env` file, replacing `path-string-to-manage.py-path` with the path to your application's `manage.py` file. + > **Tip**: you can copy the path by right clicking on the file in the Explorer view and selecting **Copy Path**. + 3. Add `"python.envFile": "${workspaceFolder}/.env"` to your `settings.json` file, so the Python extension can load the environment variables in this file when running and discovering tests (edit path as necessary if `.env` is not at root). + 4. Add Django test arguments to `"python.testing.unittestArgs": []` in `settings.json` as needed, and remove any arguments that are not compatible with Django. + +Navigate to the Testing view, and select the **Refresh Tests** button to have your Django tests displayed! + +### Troubleshooting +If your Django unit tests are not showing in the Testing view, try the following troubleshooting steps: + +- Search for error messages in the **Python** output panel. They may provide helpful hints as to why your tests are not being discovered. +- Try [running the Django tests in the terminal](https://docs.djangoproject.com/en/dev/topics/testing/overview/#running-tests). Then "translate" the same command into VS Code settings. For example, if you run `python manage.py test --arg` in the terminal, you would add `MANAGE_PY_PATH='./manage.py'` to a `.env` file, and set `"python.testing.unittestArgs": [--arg]` in the VS Code's settings. You can also check the **Python** output panel as it displays the commands that are ran by the Python extension. +- Attempt using the absolute path for `manage.py` when setting the `MANAGE_PY_PATH` environment variable, if you initially tried using the relative path. + ## IntelliSense for pytest [Pylance](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance) offers IntelliSense features that can help you work more efficiently with [pytest fixtures](https://docs.pytest.org/en/6.2.x/fixture.html) and [parameterized tests](https://docs.pytest.org/en/6.2.x/parametrize.html). From 75a2e4e5a83764a1ec36a67fc22b5681eb3ae3c3 Mon Sep 17 00:00:00 2001 From: Luciana Abud <45497113+luabud@users.noreply.github.com> Date: Fri, 30 Aug 2024 08:29:23 -0700 Subject: [PATCH 08/11] Apply suggestions from code review Co-authored-by: Nick Trogh <1908215+ntrogh@users.noreply.github.com> --- docs/python/testing.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/docs/python/testing.md b/docs/python/testing.md index 27b2db7172..4c96f929c9 100644 --- a/docs/python/testing.md +++ b/docs/python/testing.md @@ -315,25 +315,29 @@ Below are all the supported commands for testing with the Python extension in VS ## Django unit tests -The Python extension also offers support for discovering and running Django unit tests! You can get your Django tests discovered with only a few additional set up steps. +The Python extension also offers support for discovering and running Django unit tests! You can get your Django tests discovered with only a few additional setup steps: -1. Set `"python.testing.unittestEnabled": true,` in your `settings.json`. +1. Set `"python.testing.unittestEnabled": true,` in your `settings.json` [file](/docs/getstarted/settings.md#settingsjson). 2. Add `MANAGE_PY_PATH` as an environment variable: - 1. Create a file named `.env` at the root of your project. - 2. Add `MANAGE_PY_PATH='path-string-to-manage.py-path'` to the `.env` file, replacing `path-string-to-manage.py-path` with the path to your application's `manage.py` file. + 1. Create a `.env` file at the root of your project. + 2. Add `MANAGE_PY_PATH=''` to the `.env` file, replacing `` with the path to your application's `manage.py` file. > **Tip**: you can copy the path by right clicking on the file in the Explorer view and selecting **Copy Path**. - 3. Add `"python.envFile": "${workspaceFolder}/.env"` to your `settings.json` file, so the Python extension can load the environment variables in this file when running and discovering tests (edit path as necessary if `.env` is not at root). - 4. Add Django test arguments to `"python.testing.unittestArgs": []` in `settings.json` as needed, and remove any arguments that are not compatible with Django. + 3. Add `"python.envFile": "${workspaceFolder}/.env"` to your `settings.json` [file](/docs/getstarted/settings.md#settingsjson), so the Python extension can load the environment variables in this file when running and discovering tests. + > **Note**: Modify the path to the `.env` file if it's not at the root of your project. + 4. Add Django test arguments to `"python.testing.unittestArgs": []` in the `settings.json` [file](/docs/getstarted/settings.md#settingsjson) as needed, and remove any arguments that are not compatible with Django. Navigate to the Testing view, and select the **Refresh Tests** button to have your Django tests displayed! ### Troubleshooting If your Django unit tests are not showing in the Testing view, try the following troubleshooting steps: -- Search for error messages in the **Python** output panel. They may provide helpful hints as to why your tests are not being discovered. -- Try [running the Django tests in the terminal](https://docs.djangoproject.com/en/dev/topics/testing/overview/#running-tests). Then "translate" the same command into VS Code settings. For example, if you run `python manage.py test --arg` in the terminal, you would add `MANAGE_PY_PATH='./manage.py'` to a `.env` file, and set `"python.testing.unittestArgs": [--arg]` in the VS Code's settings. You can also check the **Python** output panel as it displays the commands that are ran by the Python extension. -- Attempt using the absolute path for `manage.py` when setting the `MANAGE_PY_PATH` environment variable, if you initially tried using the relative path. +- Search for error messages in the **Python** Output panel. They might provide a hint as to why your tests are not being discovered. +- Try to [run the Django tests in the terminal](https://docs.djangoproject.com/en/dev/topics/testing/overview/#running-tests). Then "translate" the same command into VS Code settings. + For example, if you run `python manage.py test --arg` in the terminal, you would add `MANAGE_PY_PATH='./manage.py'` to a `.env` file, and set `"python.testing.unittestArgs": [--arg]` in the VS Code settings. + + Alternatively, you can also find the commands that are run by the Python extension in the **Python** Output panel. +- Use the absolute path to the `manage.py` file when setting the `MANAGE_PY_PATH` environment variable, if you initially used the relative path. ## IntelliSense for pytest From 2946ebd8914821ed78839ad952b83523c0c4ee8d Mon Sep 17 00:00:00 2001 From: Courtney Webster <60238438+cwebster-99@users.noreply.github.com> Date: Wed, 4 Sep 2024 21:49:03 +0000 Subject: [PATCH 09/11] Moving adding .env to settings as a note --- docs/python/testing.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/python/testing.md b/docs/python/testing.md index 4c96f929c9..567ee86916 100644 --- a/docs/python/testing.md +++ b/docs/python/testing.md @@ -323,10 +323,10 @@ The Python extension also offers support for discovering and running Django unit 1. Create a `.env` file at the root of your project. 2. Add `MANAGE_PY_PATH=''` to the `.env` file, replacing `` with the path to your application's `manage.py` file. > **Tip**: you can copy the path by right clicking on the file in the Explorer view and selecting **Copy Path**. - 3. Add `"python.envFile": "${workspaceFolder}/.env"` to your `settings.json` [file](/docs/getstarted/settings.md#settingsjson), so the Python extension can load the environment variables in this file when running and discovering tests. - > **Note**: Modify the path to the `.env` file if it's not at the root of your project. 4. Add Django test arguments to `"python.testing.unittestArgs": []` in the `settings.json` [file](/docs/getstarted/settings.md#settingsjson) as needed, and remove any arguments that are not compatible with Django. +> **Note**: By default, the Python extension looks for and loads `.env` files at the project root. If your `.env` file is not at the project root or you are using [VS Code variable substitution](https://code.visualstudio.com/docs/editor/variables-reference), add `"python.envFile": "${workspaceFolder}/"` to your `settings.json` [file](/docs/getstarted/settings.md#settingsjson), so the Python extension can load the environment variables in this file when running and discovering tests. See our [Python environment variables](https://code.visualstudio.com/docs/python/environments#_environment-variables) docs for more information on environment variables. + Navigate to the Testing view, and select the **Refresh Tests** button to have your Django tests displayed! ### Troubleshooting @@ -334,8 +334,8 @@ If your Django unit tests are not showing in the Testing view, try the following - Search for error messages in the **Python** Output panel. They might provide a hint as to why your tests are not being discovered. - Try to [run the Django tests in the terminal](https://docs.djangoproject.com/en/dev/topics/testing/overview/#running-tests). Then "translate" the same command into VS Code settings. - For example, if you run `python manage.py test --arg` in the terminal, you would add `MANAGE_PY_PATH='./manage.py'` to a `.env` file, and set `"python.testing.unittestArgs": [--arg]` in the VS Code settings. - + For example, if you run `python manage.py test --arg` in the terminal, you would add `MANAGE_PY_PATH='./manage.py'` to a `.env` file, and set `"python.testing.unittestArgs": [--arg]` in the VS Code settings. + Alternatively, you can also find the commands that are run by the Python extension in the **Python** Output panel. - Use the absolute path to the `manage.py` file when setting the `MANAGE_PY_PATH` environment variable, if you initially used the relative path. From 625e6d8128ee00285bd9d23acba321b38f7f0d8b Mon Sep 17 00:00:00 2001 From: Nick Trogh <1908215+ntrogh@users.noreply.github.com> Date: Thu, 5 Sep 2024 09:16:38 +0200 Subject: [PATCH 10/11] Updates from editor --- docs/python/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/python/testing.md b/docs/python/testing.md index 567ee86916..04d03f6cc6 100644 --- a/docs/python/testing.md +++ b/docs/python/testing.md @@ -323,7 +323,7 @@ The Python extension also offers support for discovering and running Django unit 1. Create a `.env` file at the root of your project. 2. Add `MANAGE_PY_PATH=''` to the `.env` file, replacing `` with the path to your application's `manage.py` file. > **Tip**: you can copy the path by right clicking on the file in the Explorer view and selecting **Copy Path**. - 4. Add Django test arguments to `"python.testing.unittestArgs": []` in the `settings.json` [file](/docs/getstarted/settings.md#settingsjson) as needed, and remove any arguments that are not compatible with Django. +3. Add Django test arguments to `"python.testing.unittestArgs": []` in the `settings.json` [file](/docs/getstarted/settings.md#settingsjson) as needed, and remove any arguments that are not compatible with Django. > **Note**: By default, the Python extension looks for and loads `.env` files at the project root. If your `.env` file is not at the project root or you are using [VS Code variable substitution](https://code.visualstudio.com/docs/editor/variables-reference), add `"python.envFile": "${workspaceFolder}/"` to your `settings.json` [file](/docs/getstarted/settings.md#settingsjson), so the Python extension can load the environment variables in this file when running and discovering tests. See our [Python environment variables](https://code.visualstudio.com/docs/python/environments#_environment-variables) docs for more information on environment variables. From df4f2fc5a6b89b00f6ce657986dfe8622ca4e86e Mon Sep 17 00:00:00 2001 From: Nick Trogh <1908215+ntrogh@users.noreply.github.com> Date: Thu, 5 Sep 2024 09:17:46 +0200 Subject: [PATCH 11/11] Update docs/python/testing.md --- docs/python/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/python/testing.md b/docs/python/testing.md index 04d03f6cc6..683c2d7c12 100644 --- a/docs/python/testing.md +++ b/docs/python/testing.md @@ -325,7 +325,7 @@ The Python extension also offers support for discovering and running Django unit > **Tip**: you can copy the path by right clicking on the file in the Explorer view and selecting **Copy Path**. 3. Add Django test arguments to `"python.testing.unittestArgs": []` in the `settings.json` [file](/docs/getstarted/settings.md#settingsjson) as needed, and remove any arguments that are not compatible with Django. -> **Note**: By default, the Python extension looks for and loads `.env` files at the project root. If your `.env` file is not at the project root or you are using [VS Code variable substitution](https://code.visualstudio.com/docs/editor/variables-reference), add `"python.envFile": "${workspaceFolder}/"` to your `settings.json` [file](/docs/getstarted/settings.md#settingsjson), so the Python extension can load the environment variables in this file when running and discovering tests. See our [Python environment variables](https://code.visualstudio.com/docs/python/environments#_environment-variables) docs for more information on environment variables. +> **Note**: By default, the Python extension looks for and loads `.env` files at the project root. If your `.env` file is not at the project root or you are using [VS Code variable substitution](/docs/editor/variables-reference.md), add `"python.envFile": "${workspaceFolder}/"` to your `settings.json` [file](/docs/getstarted/settings.md#settingsjson). This enables the Python extension to load the environment variables from this file when running and discovering tests. Get more info about [Python environment variables](/docs/python/environments.md#_environment-variables). Navigate to the Testing view, and select the **Refresh Tests** button to have your Django tests displayed!