-
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
Proposed design for Django testing on rewrite #22206
Comments
Thanks for the feature request! We are going to give the community 60 days from when this issue was created to provide 7 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue. |
Update: I have created a secondary design for how Django testing could be implemented: #22222. This is only experimental at this time but could be an improved solution because it allows the extension to directly call I put this together quickly in hopes of getting a working idea out by Django-Con but please send feedback on if this would work / what changes would need to be made (like if there is a better way than directly editing settings.json). Thanks! |
Hello everyone! As I mentioned in my last comment, we have a second design iteration for Django testing in VS Code which is drafted at #22222. I have now updated the body of this proposal to include this new design. The proposal above has new questions and information so please re-review and submit your feedback. For anyone who is just joining this thread, the proposal is up to date, as revised on 11/1/2023 with our new plan for implementation. Thanks! |
Thank you to everyone who upvoted this issue! Since the community showed interest in this feature request we will leave this issue open as something to consider implementing at some point in the future. We do encourage people to continue 👍 the first/opening comment as it helps us prioritize our work based on what the community seems to want the most. |
while enabling Django testing and optionally specifying the given setup script (DJANGO_MANAGE_PY_PATH) it seems a good idea to (optionally) specify the DJANGO_SETTINGS_MODULE (path to settings.py or any alternative module) also this could be derived from the content of Path to manage.py is required for test execution if intending to use Path to settings.py is required for test discovery if intending to use built-in {
"name": "Python: Run Django Tests",
"type": "python-unittest",
"request": "launch",
"args": ["-v"],
"env": {
"PYTHONPATH": "${workspaceFolder}",
"DJANGO_TESTING": "true",
"DJANGO_MANAGE_PY_PATH": "/path/to/manage.py",
"DJANGO_SETTINGS_MODULE": "/path/to/settings.py",
}
}, |
For what it's worth, we're using a custom runner that runs all tests in parallel, spins up coverage, lints, and spits out artifact files (happy to share the code if anyone wants it). Support for custom runners isn't super necessary for our use case. We'd probably start using vs code testing to spot-check individual tests (still very useful) and continue to run |
well, you're right. |
I've had issues with the current test functionality not reporting parallel test runs properly (they run in subprocesses). Granted, I was trying to hack things together to try and make things work. Will the new implementation be able to display test results from parallel runs? |
|
Hello everyone, are there any updates on the topic? |
When I've tried doing this through hacks in the past, I found that any test result data from other processes didn't make it back to the vscode UI. Fingers crossed that a first-party solution will "just work". |
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! |
REVISED 11/1/2023 with updates regarding a new way to implement this in vscode.
Background
With the amazing help from @mh-firouzjah, we are getting close to Django testing support in VS Code! Below is a proposed design on how Django testing would look with a few outstanding questions where we are looking for input from Django developers.
One important part of this proposal is that it will be part of the new testing rewrite (see the release notes for a short explanation of what we are working on). The rewrite will be fully stable soon but for now, it is under the experiment you can turn on by setting
"python.experiments.optInto": ["pythonTestAdapter",]
in your user settings. Additionally, this proposal is based on another proposal we are working on here, that will change how testing args are configured in VS Code for python. This will move to having separate JSON entries with args for run and discovery as well as allow for environment variables to be set. Please review this proposal as the design of the json object with the Django enablement you see below will be based on that design principle (and will therefore align will all testing argument input in python for VS Code).Proposal Introduction
Since Django testing is based off the unittest library, we will be hooking in Django test support into our rewritten testing framework for unittest. How unittest now works is the extension runs a subprocess which then calls a script for discovery or execution. These scripts extend unittest functionality to gather results and format them for return. (see more on how this would work with Django later)
User Facing Design
From a user perspective, this will look like just two additional environment variables we will introduce that you would configure on your setup. The JSON for test configuration will be the same as all other testing with our new design, but with the environment variables
"DJANGO_TESTING"
and"DJANGO_MANAGE_PY_PATH"
."DJANGO_TESTING"
when set to true will then make our script run Django setup, the default value is false."DJANGO_MANAGE_PY_PATH"
is a custom path to your manage.py you want to run and the default is just looking for manage.py in your cwd. Please add your feedback on these two environment variables below.(If you have feedback on the general json args structure please see the overarching issue)
Design Examples
not using Django at all, regular proposal design of new testing args
enable Django testing but use the default setup script
enable Django testing and specify the given setup script
Implementation
You can see the full draft of how to would look here. We have not finished discovery yet as this draft is for execution. I will outline the general steps we will take below to help you follow along with the draft's design. Feedback on the draft and design is very appreciated.
execution.py
execution.py
, the env varDJANGO_TESTING_ENABLED
is checkedDJANGO_TESTING_ENABLED
is true, rundjango_execution_runner(start_dir)
django_execution_runner
get "MANAGE_PY_PATH" env var if existscwd + "manage.py"
custom_test_runner = "django_test_runner.CustomTestRunner"
subprocess.run("")
with argspython manage_py_path test --testrunner custom_test_runner
CustomTestRunner
setkwargs["resultclass"] = UnittestTestResult
execution.py
will be used for processing resultssend
method to return data to the VS Code Python extensionmanage.py test
Questions
Conclusion
Thank you for reading this issue and we appreciate all your comments and suggestions! We are always looking for contributions to our repo so please do so if you have any interest or thread here if you don't know where to start. One important step in this process will be writing test cases which we will need many different suggestions on what cases to cover.
The text was updated successfully, but these errors were encountered: