Repository navigation
Django test discovery passes incompatible default arguments to manage.py test #26163
Description
Does this issue occur when all extensions are disabled?: No — the Microsoft Python extension is required to reproduce the issue.
- VS Code Version: 1.130.0, 1b6a188127eeaf9194f945eb6eb89a657e93c54c, arm64
- Python extension version: -
- OS Version: macOS Tahoe 26.5.2 (25F84)
- Python Version: 3.14
- Django Version: 6.0.7
Steps to Reproduce
- Open a Django project with
manage.pyin the workspace root. - Follow the documented Django unittest setup:
https://code.visualstudio.com/docs/python/testing#_django-unit-tests - Set the required environment variables, including
MANAGE_PY_PATHandDJANGO_SETTINGS_MODULE. - Enable unittest discovery without explicitly configuring
python.testing.unittestArgs. - Open the Testing view or run Python: Discover Tests.
Actual Behaviour
The Python extension runs Django test discovery using:
/Users/kamil/Projects/reactor/.venv/bin/python /Users/kamil/Projects/reactor/manage.py test --testrunner=django_test_runner.CustomDiscoveryTestRunner -v -s . -p '*test*.py'
These appear to be the default arguments intended for Python's standard unittest discover command:
-v -s . -p *test*.py
They are not valid as-is for Django's manage.py test command.
1. -v is used incorrectly
For Django, -v is an alias for --verbosity and requires a value:
-v {0,1,2,3}
Passing only -v therefore causes argument parsing to fail:
manage.py test: error: argument -v/--verbosity: expected one argument
2. -s is not a valid Django test option
Django's manage.py test command does not provide a -s option.
The -s . pair belongs to python -m unittest discover, where -s specifies the start directory. Passing it to manage.py test is therefore incompatible with Django's command-line interface.
Expected Behaviour
When Django test discovery is enabled through MANAGE_PY_PATH, the extension should not pass the default unittest discover arguments to manage.py test.
Django discovery should work with the documented configuration and without requiring users to override the default test arguments manually.
Workaround
Explicitly setting an empty argument list makes discovery work:
{
"python.testing.unittestArgs": []
}Recommendation
Do not provide any default test arguments when invoking Django's test command.
In other words, when Django discovery is active, the command should be based on:
python manage.py test --testrunner=django_test_runner.CustomDiscoveryTestRunnerAny additional arguments should come only from an explicit user configuration.
This avoids passing options that belong to unittest discover but have different meanings, require different values, or do not exist in Django's test command.
Relevant Log
2026-07-29 08:27:41.543 [info] Started unittest discovery subprocess (environment extension) for workspace /Users/kamil/Projects/reactor
2026-07-29 08:27:41.797 [error] usage: manage.py test [-h] [--noinput] [--testrunner TESTRUNNER] [--failfast]
[-t TOP_LEVEL] [-p PATTERN] [--keepdb]
[--shuffle [SEED]] [-r] [--debug-mode] [-d]
[--parallel [N]] [--tag TAGS]
[--exclude-tag EXCLUDE_TAGS] [--pdb] [-b]
[--no-faulthandler] [--timing] [-k TEST_NAME_PATTERNS]
[--durations N] [--version] [-v {0,1,2,3}]
[--settings SETTINGS] [--pythonpath PYTHONPATH]
[--traceback] [--no-color] [--force-color]
[test_label ...]
manage.py test: error: argument -v/--verbosity: expected one argument
Django test discovery process exited with non-zero error code See stderr above for more details.
2026-07-29 08:27:41.797 [info] MANAGE_PY_PATH is set, running Django discovery with path to manage.py as: $/Users/kamil/Projects/reactor/manage.py
Running Django tests with command: ['/Users/kamil/Projects/reactor/.venv/bin/python', '/Users/kamil/Projects/reactor/manage.py', 'test', '--testrunner=django_test_runner.CustomDiscoveryTestRunner', '-v', '-s', '.', '-p', '*test*.py']
2026-07-29 08:27:41.805 [info] Unittest discovery completed for workspace /Users/kamil/Projects/reactor
2026-07-29 08:27:41.805 [info] [test-by-project] Project reactor (Python 3.14) discovery completed
2026-07-29 08:27:41.805 [info] [test-by-project] Discovery complete: 1/1 projects completed
Activity
jack121200 commentedon Jul 29, 2026
Hi! I'd like to work on this issue if it's available.
Would it be okay if I submitted a PR?
paduszyk commentedon Jul 29, 2026
Eleanor Boyd (@eleanorjboyd) Let me decide until Friday. I will do my best to contribute (or at least try).
But first I would like to know what is the best solution in your opinion?
--testrunner=django_test_runner.CustomDiscoveryTestRunner).-vflag and removing-s.I am definitely for 1. If 2, then we need to decide which level of verbosity to choose. IMHO, that's the user preference.
paduszyk commentedon Aug 19, 2026
Eleanor Boyd (@eleanorjboyd) I have decided to give it a try and clear the defaults for
unittest.BTW. Sorry for #26120; it uses invalid branch name.