from __future__ import unicode_literals

from django.db import connection


def pytest_report_header(config):
    with connection.cursor() as cursor:
        cursor.execute("SELECT VERSION()")
        version = cursor.fetchone()[0]
    return "MySQL version: {}".format(version)

from __future__ import unicode_literals

import django
from django.db import connection


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

    if hasattr(connection, '_nodb_connection'):
        with connection._nodb_connection.cursor() as cursor:
            cursor.execute("SELECT VERSION()")
            version = cursor.fetchone()[0]
        header += "\nMySQL version: {}".format(version)

    return header

Fix pytest version report when database does not exist, add Django version header
Fix pytest version report when database does not exist, add Django version header

  from __future__ import unicode_literals
  
+ import django
  from django.db import connection
  
  
  def pytest_report_header(config):
+     dot_version = '.'.join(str(x) for x in django.VERSION)
+     header = "Django version: " + dot_version
-     with connection.cursor() as cursor:
-         cursor.execute("SELECT VERSION()")
-         version = cursor.fetchone()[0]
-     return "MySQL version: {}".format(version)
  
+     if hasattr(connection, '_nodb_connection'):
+         with connection._nodb_connection.cursor() as cursor:
+             cursor.execute("SELECT VERSION()")
+             version = cursor.fetchone()[0]
+         header += "\nMySQL version: {}".format(version)
+ 
+     return header
+ 
Fix pytest version report when database does not exist, add Django version header
## Code Before:
from __future__ import unicode_literals

from django.db import connection


def pytest_report_header(config):
    with connection.cursor() as cursor:
        cursor.execute("SELECT VERSION()")
        version = cursor.fetchone()[0]
    return "MySQL version: {}".format(version)

## Instruction:
Fix pytest version report when database does not exist, add Django version header
## Code After:
from __future__ import unicode_literals

import django
from django.db import connection


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

    if hasattr(connection, '_nodb_connection'):
        with connection._nodb_connection.cursor() as cursor:
            cursor.execute("SELECT VERSION()")
            version = cursor.fetchone()[0]
        header += "\nMySQL version: {}".format(version)

    return header
