from __future__ import annotations

import warnings

import django
from django.db import connection
from pytest_django.plugin import blocking_manager_key


def pytest_report_header(config):
    dot_version = ".".join(str(x) for x in django.VERSION)
    header = "Django version: " + dot_version

    pytest_django_db_blocker = config.stash[blocking_manager_key]
    with pytest_django_db_blocker.unblock(), connection._nodb_cursor() as cursor:
        cursor.execute("SELECT VERSION()")
        version = cursor.fetchone()[0]
        header += f"\nMySQL version: {version}"

    return header


# MySQL 5.7 warns about some sql mode changes
warnings.filterwarnings("ignore", r".*Changing sql mode.*")
warnings.filterwarnings("ignore", r".*sql modes should be used with strict mode.*")
# MySQL 5.7 turned 'explain' into 'explain extended' so it always warns the
# optimized query
warnings.filterwarnings("ignore", r".*/\* select#\d+ \*/")
# MySQL 5.7 deprecated some query hints
warnings.filterwarnings("ignore", r".*'SQL_CACHE' is deprecated.*")
warnings.filterwarnings("ignore", r".*'SQL_NO_CACHE' is deprecated.*")
