Django: Unit Test Fixtures not loading in VSCode Debug Mode
I have written some unit tests with Django, with fixtures set up. I want to debug these tests and have a configuration on VSCode to do this...
{
// 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": "Django: Test Unit Case",
"type": "debugpy",
"request": "launch",
"args": [
"test",
"apps.students",
"-v 2"
],
"django": true,
"autoStartBrowser": false,
"program": "${workspaceFolder}\\server\\manage.py"
},
...
]
}
I have my FIXTURE_DIR configured correctly, as when I run the command py manage.py test apps.students
, the fixtures load and give no error. However, when I try to run and debug, I get the following error...
Found 6 test(s).
Creating test database for alias 'default' ('file:memorydb_default?mode=memory&cache=shared')...
Operations to perform:
Synchronize unmigrated apps: corsheaders, django_extensions, messages, rest_framework, staticfiles
Apply all migrations: admin, auth, ballots, contenttypes, election_count_strategies, polls, programme_groupings, programmes, sessions, students, token_blacklist, users, year_groups
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Running migrations:
Applying contenttypes.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0001_initial... OK
...
System check identified no issues (0 silenced).
setUpClass (apps.students.tests.YearRepresentiveTestCase) ... ERROR
======================================================================
ERROR: setUpClass (apps.students.tests.YearRepresentiveTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\fiona\AppData\Roaming\Python\Python312\site-packages\django\test\testcases.py", line 1389, in setUpClass
call_command(
File "C:\Users\fiona\AppData\Roaming\Python\Python312\site-packages\django\core\management\__init__.py", line 194, in call_command
return command.execute(*args, **defaults)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\fiona\AppData\Roaming\Python\Python312\site-packages\django\core\management\base.py", line 459, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\fiona\AppData\Roaming\Python\Python312\site-packages\django\core\management\commands\loaddata.py", line 103, in handle
self.loaddata(fixture_labels)
File "C:\Users\fiona\AppData\Roaming\Python\Python312\site-packages\django\core\management\commands\loaddata.py", line 156, in loaddata
if self.find_fixtures(fixture_label):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\fiona\AppData\Roaming\Python\Python312\site-packages\django\core\management\commands\loaddata.py", line 351, in find_fixtures
raise CommandError("No fixture named '%s' found." % fixture_name)
django.core.management.base.CommandError: No fixture named 'students' found.
----------------------------------------------------------------------
Ran 0 tests in 0.065s
FAILED (errors=1)
Destroying test database for alias 'default' ('file:memorydb_default?mode=memory&cache=shared')...
I have my FIXTURE_DIR
set up in my settings.py
...
FIXTURE_DIRS = [
'fixtures'
]
Why are my fixtures loading fine when I run py manage.py test apps.students
in the command line, but not when I use run and debug with VSCode's debugger? Thank you for any help!