Adapt 'warnings-as-errors' option to allow taking migration test codes as input

This commit is contained in:
David Wobrock committed 2022-03-13 17:26:40 +01:00
1 parent a04ecc078a
commit c7d9129db9
8 files changed
+114 -33

No files matched your search

@@ -11,7 +11,11 @@ from django.core.management.base import BaseCommand
from ...constants import __version__
from ...migration_linter import MessageType, MigrationLinter
from ...sql_analyser.analyser import ANALYSER_STRING_MAPPING
from ..utils import configure_logging, register_linting_configuration_options
from ..utils import (
configure_logging,
extract_warnings_as_errors_option,
register_linting_configuration_options,
)
CONFIG_NAME = "django_migration_linter"
PYPROJECT_TOML = "pyproject.toml"
@@ -155,6 +159,11 @@ class Command(BaseCommand):
if not options[k]:
options[k] = v
(
warnings_as_errors_tests,
all_warnings_as_errors,
) = extract_warnings_as_errors_option(options["warnings_as_errors"])
linter = MigrationLinter(
settings_path,
ignore_name_contains=options["ignore_name_contains"],
@@ -170,7 +179,8 @@ class Command(BaseCommand):
only_unapplied_migrations=options["unapplied_migrations"],
exclude_migration_tests=options["exclude_migration_tests"],
quiet=options["quiet"],
warnings_as_errors=options["warnings_as_errors"],
warnings_as_errors_tests=warnings_as_errors_tests,
all_warnings_as_errors=all_warnings_as_errors,
no_output=options["verbosity"] == 0,
analyser_string=options["sql_analyser"],
)
@@ -9,7 +9,11 @@ from django.db.migrations.writer import MigrationWriter
from django_migration_linter import MigrationLinter
from ..utils import configure_logging, register_linting_configuration_options
from ..utils import (
configure_logging,
extract_warnings_as_errors_option,
register_linting_configuration_options,
)
def ask_should_keep_migration():
@@ -68,13 +72,19 @@ class Command(MakeMigrationsCommand):
else default_should_keep_migration
)
(
warnings_as_errors_tests,
all_warnings_as_errors,
) = extract_warnings_as_errors_option(self.warnings_as_errors)
# Lint migrations
linter = MigrationLinter(
path=os.environ["DJANGO_SETTINGS_MODULE"],
database=self.database,
no_cache=True,
exclude_migration_tests=self.exclude_migrations_tests,
warnings_as_errors=self.warnings_as_errors,
warnings_as_errors_tests=warnings_as_errors_tests,
all_warnings_as_errors=all_warnings_as_errors,
)
for app_label, app_migrations in changes.items():