Unit test the equivalent of manage.py "system checks"

When starting up Django using the default manage.py runserver it performs system checks:

Performing system checks...

Watching for file changes with StatReloader
System check identified no issues (0 silenced).
May 18, 2023 - 16:48:17
Django version 4.1.9, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Is there anyway to run the equivalent to these checks, but using a test runner such as pytest so that CI would fail if any of these system checks would have failed?

1 Like

It looks like both runserver and check run the check method in django.core.management.base.BaseCommand, which looks to me to use django.core.checks.

My guess would be that you could do the same thing.

See System check framework | Django documentation | Django and System check framework | Django documentation | Django

I also just learned that you can run:

python manage.py check --settings config.settings --fail-level DEBUG --verbosity 3

This is probably preferred since it’s documented and manage.py presumably has all of the settings and other things needed.

I’ll probably add this to my noxfile.py to run just before pytest is invoked.