Skip to content

Django test discovery passes incompatible default arguments to manage.py test #327966

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, 1b6a188, arm64
  • Python extension version: -
  • OS Version: macOS Tahoe 26.5.2 (25F84)
  • Python Version: 3.14
  • Django Version: 6.0.7

Steps to Reproduce

  1. Open a Django project with manage.py in the workspace root.
  2. Follow the documented Django unittest setup:
    https://code.visualstudio.com/docs/python/testing#_django-unit-tests
  3. Set the required environment variables, including MANAGE_PY_PATH and DJANGO_SETTINGS_MODULE.
  4. Enable unittest discovery without explicitly configuring python.testing.unittestArgs.
  5. 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.CustomDiscoveryTestRunner

Any 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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions