-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature suggestion: run Django unittests #73
Feature suggestion: run Django unittests #73
Comments
From @guhuajun on January 19, 2017 6:51 I did something like following. I think it's supported now. |
From @jvaesteves on January 19, 2017 12:13 I tried your suggestion, copying the same parameters on the settings.json file, but running the "Run Unit Test Method..." command still doesn't work. The Output Console gives me the following message: ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. And then, when I configure this environment variable to my global_settings.py path, the message change to: ImportError: Import by filename is not supported. |
From @guhuajun on January 20, 2017 0:22 https://github.com/DonJayamanne/pythonVSCode/wiki/unitest-(Standard-Unit-testing)-Framework#test-discovery Yes, missing DJANGO_SETTINGS_MODULE is annoying. I encountered this issue when writing tests for a django-cms project. |
@jvaesteves Will be closing this issue as @guhuajun has a solution. |
@jvaesteves please confirm @guhuajun suggestion works, so I can close this issue. |
From @jvaesteves on February 2, 2017 10:46 No, it didn't. |
From @james-perretta on March 5, 2017 4:35 It looks to me like the suggestion from @guhuajun gets us part of the way there for running Django test cases. Unless I'm mistaken, you can't really use unittest to run tests for any serious Django project. I did a bit of digging, and although I'm not particularly familiar with the implementation details of your plugin, I think this is a starter summary of what it would require to add this:
Thoughts? |
From @PlugaruT on October 3, 2017 11:15 Because I have different settings files for each environment (production, local, test), I can't run tests because with this plugin because |
@PlugaruT Environment variables can be set for the workspace. Just create a file named |
Any update here?, I have a bunch of tests file, I'm not sure where to put |
You don't need to configure DJANGO_SETTINGS_MODULE if you use the option: "--settings < filesetting >" Just saying because maybe we can make thah unittest plugin doesn't need env variable, just tell him the setting and if not, use default. And just one question about my closed issue. My problem is not implementation of new feature for django. But tests are not DISCOVERED at all. I could make them run at least in part, but if it doesn't discover them I can't. When I use |
Any decision on this? This is somewhat of a small ask, but it will make dev work better for those who use django and not pytest/nose/etc. |
@yardensachs not at the moment (we're tied up with other things that impact all Python developers). If anyone wants to submit a PR to introduce a fix for this we would happily review it. |
So.. any update on this? I tried setting up our company project with VSCode and the extension is still unable to find django test modules. |
Apparently the next step is here and we need votes to get things going. If the 300+ people who liked this post could make their voices heard. |
@khamaileon Nice. Good spot. I didn't even know about that other issue. |
As long as the proposed procedure is taking approval, I have tested a new idea, and it worked well for me. I am awaiting feedback and information on whether it works properly for you and others, or if there are any issues.
1- Vscode Python Extension Requirement try:
import django
django.setup()
except:
pass 2- Django Project Requirement DJANGO_SETTINGS_MODULE=my_django_project_name.settings |
@mh-firouzjah I tried but it didn't work out. Here's my vscode settings: {
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"editor.formatOnSave": true,
"python.defaultInterpreterPath": "~/.virtualenvs/acme-api/bin/python",
"python.envFile": "${workspaceFolder}/.env.local",
"editor.rulers": [100],
"python.testing.unittestArgs": ["-v", "-s", "./src", "-p", "test*.py"],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
} And here's the kind of output I got:
DJANGO_SETTINGS_MODULE=project.settings is read correctly, otherwise I'm told it's necessary. The problem may be that my code is in a src folder and not in the root. 🤷♂️ |
hi @khamaileon, |
Yet I'm able to launch it with the manage command inside vscode and outside (from the src folder). {
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/src/manage.py",
"args": ["runserver"],
"django": true,
"envFile": "${workspaceFolder}/.env.local",
"justMyCode": true
}
]
} |
Thank you @mh-firouzjah! Your solution works great :) |
Hello Everyone! The long requested ask is live!! Django tests are now supported in the VS Code python extension! Currently this is pre-release and would greatly appreciate Django users try this out and give feedback / submit bugs! (there will likely be bugs so I appeciate your patience as we work through them) Steps:
Thank you! |
@eleanorjboyd just some quick spelling mistakes to save anyone copy pasting:
And some very initial feedback:
This is reproducible against a generated Django v5.1 project created with LMK if you want me to flesh this out into a proper GH issue. |
Hi @swebra thank you for trying it! Ill make those fixes to the instructions. So for the args, you should be able to go into |
Ah of course. Test execution now works as expected in the generated project! The only thing else of note there is a rogue error without any message during test discovery, just before the
|
hm yes I see that error- ill see if I can track it down. Does it change the outcome of the discovery or just appears in the logs? |
Just appears in the logs as far as I can tell. |
From @jvaesteves on January 16, 2017 22:28
Django unittest extends from unittests, but you can't run as the former on this extension. For this, you need to "manage.py test", but it would be awesome if there were those same shortcuts.
Copied from original issue: DonJayamanne/pythonVSCode#648
The text was updated successfully, but these errors were encountered: