Skip to content

Conversation

@cwebster-99
Copy link
Member

Updating python/testing.md to include setup and troubleshooting for Django testing.

Copy link
Member

@eleanorjboyd eleanorjboyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great thank you! Added few comments

- 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).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some users have run into the problem that we populate python.testing.unittestArgs if they go through the UI setup flow right now and these args don't work for Django. Could we add somewhere to edit that variable to remove args and add any Django necessary args

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this reminder up to the steps

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to remind people how to change logging verbosity or is that elsewhere in our docs?

Co-authored-by: Luciana Abud <45497113+luabud@users.noreply.github.com>
Copy link
Contributor

@ntrogh ntrogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some minor text suggestions.

luabud and others added 2 commits August 27, 2024 16:42
Co-authored-by: Nick Trogh <1908215+ntrogh@users.noreply.github.com>
@luabud luabud marked this pull request as ready for review August 29, 2024 01:22
@vs-code-engineering vs-code-engineering bot added this to the August 2024 milestone Aug 29, 2024
Copy link
Contributor

@ntrogh ntrogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! I added a few final text suggestions.

Co-authored-by: Nick Trogh <1908215+ntrogh@users.noreply.github.com>
ntrogh
ntrogh previously approved these changes Aug 30, 2024
Copy link
Contributor

@ntrogh ntrogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

> **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.

> **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}/<path-to-.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. See our [Python environment variables](https://code.visualstudio.com/docs/python/environments#_environment-variables) docs for more information on environment variables.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luabud @ntrogh I moved this step to a note since this step is not needed to get it working by default. Please suggest edits as needed!

cc/ @eleanorjboyd

1. Create a `.env` file at the root of your project.
2. Add `MANAGE_PY_PATH='<path-to-manage.py>'` to the `.env` file, replacing `<path-to-manage.py>` 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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Member Author

@cwebster-99 cwebster-99 Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this step be nested or represented top-level # 3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should probably be top-level #3 because it is not part of setting that environment variable.

Copy link
Contributor

@ntrogh ntrogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor formatting updates

@ntrogh
Copy link
Contributor

ntrogh commented Sep 5, 2024

@cwebster-99 merging this PR to make sure it's included in today's release.

@ntrogh ntrogh removed the don't merge label Sep 5, 2024
@ntrogh ntrogh merged commit f7bd9cf into main Sep 5, 2024
@ntrogh ntrogh deleted the python-django-tests branch September 5, 2024 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants