microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.11k stars 29.27k forks source link

New Django test feature: can't find '__main__' module #233404

Closed khamaileon closed 1 hour ago

khamaileon commented 2 hours ago

Type: Bug

Hello team vscode-python, @eleanorjboyd ,

I finally had some time to try the new Django testing in VSCode. Unfortunately, I couldn't get it to work.

Here the log output:

2024-10-24 15:18:07.895 [info] 

2024-10-24 15:18:08.535 [info] Discover tests for workspace name: my-project - uri: /Users/me/workspace/company/my-project
2024-10-24 15:18:08.535 [info] Running discovery for unittest using the new test adapter.
2024-10-24 15:18:08.540 [info] Discovering unittest tests for workspace /Users/me/workspace/company/my-project with arguments: /Users/me/.vscode/extensions/ms-python.python-2024.16.1-darwin-arm64/python_files/unittestadapter/discovery.py,--udiscovery

2024-10-24 15:18:08.540 [info] > ~/.virtualenvs/my-project/bin/python ~/.vscode/extensions/ms-python.python-2024.16.1-darwin-arm64/python_files/unittestadapter/discovery.py --udiscovery
2024-10-24 15:18:08.541 [info] cwd: .
2024-10-24 15:18:08.599 [info] MANAGE_PY_PATH is set, running Django discovery with path to manage.py as: $/Users/me/workspace/company/my-project/src

2024-10-24 15:18:08.599 [info] Running Django tests with command: ['/Users/me/.virtualenvs/my-project/bin/python', '/Users/me/workspace/company/my-project/src', 'test', '--testrunner=django_test_runner.CustomDiscoveryTestRunner']

2024-10-24 15:18:08.621 [error] /Users/me/.virtualenvs/my-project/bin/python: can't find '__main__' module in '/Users/me/workspace/company/my-project/src'

2024-10-24 15:18:08.621 [info]

My settings.json:

{
  "editor.codeActionsOnSave": {
    "source.organizeImports": "explicit"
  },
  "editor.formatOnSave": true,
  "editor.rulers": [100],
  "isort.args": ["--profile", "black"],
  "notebook.codeActionsOnSave": {
    "source.organizeImports": "explicit"
  },
  "notebook.formatOnSave.enabled": true,
  "python.envFile": "${workspaceFolder}/.env.local",
  "python.experiments.optInto": ["pythonTestAdapter"],
  "python.testing.pytestEnabled": false,
  "python.testing.unittestArgs": [],
  "python.testing.unittestEnabled": true
}

My launch.json:

{
  // 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 Debugger: Django",
      "type": "debugpy",
      "request": "launch",
      "args": ["runserver", "0.0.0.0:8000"],
      "django": true,
      "autoStartBrowser": true,
      "program": "${workspaceFolder}/src/manage.py"
    }
  ]
}

cd src && python manage.py test works well in the VS code terminal.

Since I wasn't sure that the problem wasn't due to the fact that I had a src subdirectory in my project, I redid the test with a new Django project, and I have the same issue.

VS Code version: Code 1.95.1 (Universal) (65edc4939843c90c34d61f4ce11704f09d3e5cb6, 2024-10-31T05:14:54.222Z) OS version: Darwin arm64 23.5.0 Modes:

System Info |Item|Value| |---|---| |CPUs|Apple M3 Pro (11 x 2400)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
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_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off| |Load (avg)|2, 2, 2| |Memory (System)|18.00GB (0.23GB free)| |Process Argv|. --crash-reporter-id 6a77dd1b-2544-406f-98a9-34d5a796c1c9| |Screen Reader|no| |VM|0%|
Extensions (21) Extension|Author (truncated)|Version ---|---|--- vscode-eslint|dba|3.0.10 prettier-vscode|esb|11.0.0 copilot|Git|1.243.0 copilot-chat|Git|0.22.2 language-gettext|mro|0.5.0 vscode-docker|ms-|1.29.3 black-formatter|ms-|2024.4.0 debugpy|ms-|2024.12.0 flake8|ms-|2023.10.0 isort|ms-|2023.10.1 python|ms-|2024.18.0 vscode-pylance|ms-|2024.11.1 jupyter|ms-|2024.10.0 jupyter-keymap|ms-|1.1.2 jupyter-renderers|ms-|1.0.21 vscode-jupyter-cell-tags|ms-|0.1.9 vscode-jupyter-slideshow|ms-|0.1.6 remote-containers|ms-|0.388.0 vscode-xml|red|0.27.1 vscode-lldb|vad|1.11.1 volar|Vue|2.1.10
A/B Experiments ``` vsliv368cf:30146710 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscod805cf:30301675 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:31024239 vscaat:30438848 c4g48928:30535728 azure-dev_surveyonecf:30548226 962ge761:30959799 pythongtdpath:30769146 pythonnoceb:30805159 asynctok:30898717 pythonmypyd1:30879173 h48ei257:31000450 pythontbext0:30879054 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 dsvsc021:30996838 724cj586:31013169 dvdeprecation:31068756 dwnewjupytercf:31046870 impr_priority:31102340 nativerepl2:31139839 refactort:31108082 pythonrstrctxt:31112756 cf971741:31144450 iacca1:31171482 notype1:31157159 5fd0e150:31155592 dwcopilot:31170013 ```
vs-code-engineering[bot] commented 2 hours ago

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.95.2. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

khamaileon commented 2 hours ago

I've updated to the latest release (1.95.2), but the problem persists.

khamaileon commented 1 hour ago

I moved it here: https://github.com/microsoft/vscode-python/issues/24405