Type: Bug
Behaviour
Overview
Unittest discovery fails for Django tests when following these instructions. At least, they fail for me in projects that use a Python virtualenv inside a dev container where manage.py is not at the root of the project. I'm not sure which of those factors (if any) is relevant. I was able to reproduce the issue by creating this minimal example project: https://github.com/oaahmad/sample-django-project .
Steps to reproduce:
- Clone this repo: https://github.com/oaahmad/sample-django-project
- Build the dev container
- Open the "Testing" view from the activity bar
Expected Behaviour
- The
test_sample test should be visible in the Testing view
- There should be no errors in the Testing view
Actual Behaviour
- There are no tests listed in the Testing view
- The Testing view shows the error "Error discovering unittest tests"
Screenshot:

Additional Information
The tests run without issue from the integrated terminal with ./manage.py test --noinput (from the /home/ubuntu/sample-django-project/src directory). Here is the output:
(sample-virtual-env) ~/sample-django-project/src$ ./manage.py test --noinput
Found 1 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
I ran
.
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
Destroying test database for alias 'default'...
This is part of the output in Output -> Python (I will paste the full output under "Diagnostic Data"):
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
This makes it seem like the Python extension is trying to run the tests as regular unit tests instead of using manage.py. However, I specify MANAGE_PY_PATH in a .env file, and I set "python.envFile" to that file's path (see the example project).
I tried rebuilding the dev container "without cache" multiple times. I tried different Python versions, and different Ubuntu versions for the container. I tried with both a custom user and with the ubuntu user that comes with Ubuntu 24. I tried with both Python's builtin venv package and the virtualenv package. I got the same issue every time.
Diagnostic data
Output from Python in the Output panel
2024-09-30 22:40:26.920 [info] Discover tests for workspace name: sample-django-project - uri: /home/ubuntu/sample-django-project
2024-09-30 22:40:26.922 [warning] could not find a pixi interpreter for the interpreter at /home/ubuntu/sample-virtual-env/bin/python3
2024-09-30 22:40:26.953 [info] > . ~/sample-virtual-env/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode-server/extensions/ms-python.python-2024.14.1-linux-arm64/python_files/printEnvVariables.py
2024-09-30 22:40:26.953 [info] shell: bash
2024-09-30 22:40:26.975 [warning] could not find a pixi interpreter for the interpreter at /home/ubuntu/sample-virtual-env/bin/python3
2024-09-30 22:40:26.979 [info] > ~/sample-virtual-env/bin/python3 ~/.vscode-server/extensions/ms-python.python-2024.14.1-linux-arm64/python_files/testing_tools/unittest_discovery.py . test*.py
2024-09-30 22:40:26.979 [info] cwd: ./src
2024-09-30 22:40:27.151 [error] Error discovering unittest tests:
Failed to import test module: sampleapp.tests_sample
Traceback (most recent call last):
File "/usr/lib/python3.12/unittest/loader.py", line 394, in _find_test_path
module = self._get_module_from_name(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/unittest/loader.py", line 337, in _get_module_from_name
__import__(name)
File "/home/ubuntu/sample-django-project/src/sampleapp/tests_sample.py", line 2, in <module>
from django.contrib.auth.models import User
File "/home/ubuntu/sample-virtual-env/lib/python3.12/site-packages/django/contrib/auth/models.py", line 3, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/home/ubuntu/sample-virtual-env/lib/python3.12/site-packages/django/contrib/auth/base_user.py", line 57, in <module>
class AbstractBaseUser(models.Model):
File "/home/ubuntu/sample-virtual-env/lib/python3.12/site-packages/django/db/models/base.py", line 129, in __new__
app_config = apps.get_containing_app_config(module)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/sample-virtual-env/lib/python3.12/site-packages/django/apps/registry.py", line 260, in get_containing_app_config
self.check_apps_ready()
File "/home/ubuntu/sample-virtual-env/lib/python3.12/site-packages/django/apps/registry.py", line 138, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Extension version: 2024.14.1
VS Code version: Code 1.93.1 (Universal) (38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40, 2024-09-11T17:20:05.685Z)
OS version: Darwin arm64 24.0.0
Modes:
Remote OS version: Linux arm64 6.10.4-linuxkit
- Python version (& distribution if applicable, e.g. Anaconda): 3.12.3
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
- Value of the
python.languageServer setting: Default
User Settings
envFile: "<placeholder>"
languageServer: "Pylance"
testing
• cwd: "<placeholder>"
• unittestArgs: "<placeholder>"
• unittestEnabled: true
Installed Extensions
| Extension Name |
Extension Id |
Version |
| Code Spell Checker |
streetsidesoftware.code-spell-checker |
3.0.1 |
| GitLens — Git supercharged |
eamodio.gitlens |
15.5.1 |
| JavaScript Debugger |
ms-vscode.js-debug |
1.93.0 |
| Pylance |
ms-python.vscode-pylance |
2024.9.2 |
| Python |
ms-python.python |
2024.14.1 |
| Python Debugger |
ms-python.debugpy |
2024.10.0 |
| REST Client |
humao.rest-client |
0.25.1 |
| Table Visualizer for JavaScript Profiles |
ms-vscode.vscode-js-profile-table |
1.0.9 |
System Info
| Item |
Value |
| CPUs |
Apple M1 Pro (8 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, 3, 3 |
| Memory (System) |
16.00GB (0.07GB free) |
| Process Argv |
|
| Screen Reader |
no |
| VM |
0% |
| Item |
Value |
| Remote |
Dev Container: Sample Dev Container @ desktop-linux |
| OS |
Linux arm64 6.10.4-linuxkit |
| CPUs |
unknown (8 x 0) |
| Memory (System) |
7.66GB (4.16GB free) |
| VM |
0% |
Type: Bug
Behaviour
Overview
Unittest discovery fails for Django tests when following these instructions. At least, they fail for me in projects that use a Python virtualenv inside a dev container where
manage.pyis not at the root of the project. I'm not sure which of those factors (if any) is relevant. I was able to reproduce the issue by creating this minimal example project: https://github.com/oaahmad/sample-django-project .Steps to reproduce:
Expected Behaviour
test_sampletest should be visible in the Testing viewActual Behaviour
Screenshot:

Additional Information
The tests run without issue from the integrated terminal with
./manage.py test --noinput(from the/home/ubuntu/sample-django-project/srcdirectory). Here is the output:This is part of the output in
Output->Python(I will paste the full output under "Diagnostic Data"):This makes it seem like the Python extension is trying to run the tests as regular unit tests instead of using
manage.py. However, I specifyMANAGE_PY_PATHin a.envfile, and I set"python.envFile"to that file's path (see the example project).I tried rebuilding the dev container "without cache" multiple times. I tried different Python versions, and different Ubuntu versions for the container. I tried with both a custom user and with the
ubuntuuser that comes with Ubuntu 24. I tried with both Python's builtinvenvpackage and thevirtualenvpackage. I got the same issue every time.Diagnostic data
Output from
Pythonin theOutputpanelExtension version: 2024.14.1
VS Code version: Code 1.93.1 (Universal) (38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40, 2024-09-11T17:20:05.685Z)
OS version: Darwin arm64 24.0.0
Modes:
Remote OS version: Linux arm64 6.10.4-linuxkit
python.languageServersetting: DefaultUser Settings
Installed Extensions
System Info
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