test_commands.py 1.0 KB

12345678910111213141516171819202122232425
  1. from django.core import checks
  2. from django.core.checks import Error
  3. from django.test import SimpleTestCase
  4. from django.test.utils import isolate_apps, override_settings, override_system_checks
  5. @isolate_apps("check_framework.custom_commands_app", attr_name="apps")
  6. @override_settings(INSTALLED_APPS=["check_framework.custom_commands_app"])
  7. @override_system_checks([checks.commands.migrate_and_makemigrations_autodetector])
  8. class CommandCheckTests(SimpleTestCase):
  9. def test_migrate_and_makemigrations_autodetector_different(self):
  10. expected_error = Error(
  11. "The migrate and makemigrations commands must have the same "
  12. "autodetector.",
  13. hint=(
  14. "makemigrations.Command.autodetector is int, but "
  15. "migrate.Command.autodetector is MigrationAutodetector."
  16. ),
  17. id="commands.E001",
  18. )
  19. self.assertEqual(
  20. checks.run_checks(app_configs=self.apps.get_app_configs()),
  21. [expected_error],
  22. )