Skip to content
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

Python test framework #20701

Closed
EspritElf opened this issue Feb 15, 2023 · 6 comments
Closed

Python test framework #20701

EspritElf opened this issue Feb 15, 2023 · 6 comments
Assignees
Labels
area-testing triage-needed Needs assignment to the proper sub-team

Comments

@EspritElf
Copy link

EspritElf commented Feb 15, 2023

Type: Bug

Python unit testing framework doesn't enable unit testing. Flask icon only appears when entering debug mode, but still can't Configure Python Tests. The button is there, but once the unint test settings questions are answered, nothing happens.

test_urls.py.-.test-django.-.Visual.Studio.Code.2023-02-14.21-24-12.mp4

Extension version: 2023.2.0
VS Code version: Code 1.75.1 (441438abd1ac652551dbe4d408dfcec8a499b8bf, 2023-02-08T21:32:34.589Z)
OS version: Windows_NT x64 10.0.22621
Modes:
Sandboxed: No

System Info
Item Value
CPUs 11th Gen Intel(R) Core(TM) i5-1155G7 @ 2.50GHz (8 x 2496)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) undefined
Memory (System) 11.65GB (6.07GB free)
Process Argv --crash-reporter-id 2561f754-1662-48e1-9812-e1b20b488e6e
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscoreces:30445986
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593:30376534
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
dsvsc012cf:30540253
pynewvextcfv2:30660300
azure-dev_surveyone:30548225
vsccc:30610678
pyindex848:30662994
nodejswelcome1:30587005
2e4cg342:30602488
pyind779:30662992
f6dab269:30613381
pythonsymbol12cf:30657549
a9j8j154:30646983

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 15, 2023
@karthiknadig
Copy link
Member

@EspritElf If you run unittest from terminal is it able to find it? I suspect that tests being under mysite/tests you may have to set the starting directory as mysite/tests with root as .. something like this:

python -m unittest discover -v -s mysite/tests -p test_*.py -t .

Run the above command and see if it is able to find the tests. If that works then make sure that unittest args in settings.json looks like that. IF not adjust the arguments till it does and then use it in settings.json.

@EspritElf
Copy link
Author

Hello Karth,

Still no luck inside VS code. I am using Django and I suspect one issue may be that Django's configuration settings aren't being set when using the python unittest command without calling manage.py.
I tried the command from the parent dir of mysite:

python -m unittest discover -v -s mysite/tests -p test_*.py -t .

and got this error:

File "... tests\test_urls.py", line 3, in <module>  from polls.views import vote, IndexPollView, DetailPollView
ModuleNotFoundError: No module named 'polls'

I have an __init__.py file in my polls directory.

The only way I'm able to run tests is using manage.py with the command:

python manage.py test tests.test_urls

I think my best solution is to use a batch file to run tests using manage.py.

Thanks for looking into this.

@eleanorjboyd
Copy link
Member

Hello @EspritElf! It seems you are running into the issue we see with not supporting Django testing. This is something that has recently raised a lot of interest and moved up in priority so we will hopefully get to it in the near future. Feel free to keep up to date with our repo and specifically the PRs and issues related to Django testing to follow along with progress and help if you feel inclined. Thanks!

@EspritElf
Copy link
Author

Hi Eleanor,
Thanks for the reply! I have read PR 20675 and I think that would fix my issue. If you need people for testing I would be happy to help out, but I would need some documentation on how to go about doing that. Otherwise I will wait for the new extension!
Best regards.

@karthiknadig
Copy link
Member

@EspritElf That PR #20675 cannot be taken directly. There are other ways to set django setting programmatically by directly calling from django.conf import settings and settings.configure, which the PR does not address. It runs eval on a line that specifically looks like os.environ.setdefault which may not be present in the manage.py. We haven't dismissed the solution yet, we may have to tweak the code a bit to handle more scenarios. Ideally, we will need something that can handle this in a user configurable way.

There is another issue with the way unittest discovery works currently. It prints out the discovered content to stdout. This becomes a problem when you have frameworks that can alter the output. Libraries printing out to stdout via the logging apis in python that can break our parsing. So, we need a way to directly hook into the suite processing in django, and do it in a way that does not interfere discovery and execution of tests from command line.

We are currently looking for ways to do this generally, so it can work for any manner of configuration for django, and in a way that works for a broader set of cases.

@eleanorjboyd
Copy link
Member

Hi @EspritElf, revisiting this issue and the ask seems the same as #73 so I am going to close this in favor of that long-standing issue. Updates on django test support will be made there and fingers crossed it can be soon. Thanks

@eleanorjboyd eleanorjboyd closed this as not planned Won't fix, can't repro, duplicate, stale Dec 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

3 participants