# Path: opentracing_instrumentation/client_hooks/mysqldb.py
# class MySQLdbPatcher(Patcher):
#     def _install_patches(self):
#     def _reset_patches(self):
# 
# Path: opentracing_instrumentation/request_context.py
# def span_in_context(span):
#     """
#     Create a context manager that stores the given span in the thread-local
#     request context. This function should only be used in single-threaded
#     applications like Flask / uWSGI.
# 
#     ## Usage example in WSGI middleware:
# 
#     .. code-block:: python
#         from opentracing_instrumentation.http_server import WSGIRequestWrapper
#         from opentracing_instrumentation.http_server import before_request
#         from opentracing_instrumentation import request_context
# 
#         def create_wsgi_tracing_middleware(other_wsgi):
# 
#             def wsgi_tracing_middleware(environ, start_response):
#                 request = WSGIRequestWrapper.from_wsgi_environ(environ)
#                 span = before_request(request=request, tracer=tracer)
# 
#                 # Wrapper around the real start_response object to log
#                 # additional information to opentracing Span
#                 def start_response_wrapper(status, response_headers,
#                                            exc_info=None):
#                     if exc_info is not None:
#                         span.log(event='exception', payload=exc_info)
#                     span.finish()
# 
#                     return start_response(status, response_headers)
# 
#                 with request_context.span_in_context(span):
#                     return other_wsgi(environ, start_response_wrapper)
# 
#             return wsgi_tracing_middleware
# 
#     :param span: OpenTracing Span
#     :return:
#         Return context manager that wraps the request context.
#     """
# 
#     # Return a no-op Scope if None was specified.
#     if span is None:
#         return opentracing.Scope(None, None)
# 
#     return opentracing.tracer.scope_manager.activate(span, False)
# 
# Path: tests/opentracing_instrumentation/sql_common.py
# class User(object):
#     def __init__(self, name, fullname, password):


import sys
import pytest
        import MySQLdb
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import mysqldb as mysqldb_hooks
from opentracing_instrumentation.request_context import span_in_context
from .sql_common import metadata, User





SKIP_REASON_PYTHON_3 = 'MySQLdb is not compatible with Python 3'
SKIP_REASON_CONNECTION = 'MySQL is not running or cannot connect'
MYSQL_CONNECTION_STRING = 'mysql://root@127.0.0.1/test'


@pytest.fixture
def session():
    Session = sessionmaker()
    engine = create_engine(MYSQL_CONNECTION_STRING)
    Session.configure(bind=engine)
    metadata.create_all(engine)
    try:
        yield Session()
    except:
        pass


@pytest.fixture(autouse=True, scope='module')
def patch_sqlalchemy():
    mysqldb_hooks.install_patches()
    try:
        yield
    finally:

# Path: opentracing_instrumentation/client_hooks/mysqldb.py
# class MySQLdbPatcher(Patcher):
#     def _install_patches(self):
#     def _reset_patches(self):
# 
# Path: opentracing_instrumentation/request_context.py
# def span_in_context(span):
#     """
#     Create a context manager that stores the given span in the thread-local
#     request context. This function should only be used in single-threaded
#     applications like Flask / uWSGI.
# 
#     ## Usage example in WSGI middleware:
# 
#     .. code-block:: python
#         from opentracing_instrumentation.http_server import WSGIRequestWrapper
#         from opentracing_instrumentation.http_server import before_request
#         from opentracing_instrumentation import request_context
# 
#         def create_wsgi_tracing_middleware(other_wsgi):
# 
#             def wsgi_tracing_middleware(environ, start_response):
#                 request = WSGIRequestWrapper.from_wsgi_environ(environ)
#                 span = before_request(request=request, tracer=tracer)
# 
#                 # Wrapper around the real start_response object to log
#                 # additional information to opentracing Span
#                 def start_response_wrapper(status, response_headers,
#                                            exc_info=None):
#                     if exc_info is not None:
#                         span.log(event='exception', payload=exc_info)
#                     span.finish()
# 
#                     return start_response(status, response_headers)
# 
#                 with request_context.span_in_context(span):
#                     return other_wsgi(environ, start_response_wrapper)
# 
#             return wsgi_tracing_middleware
# 
#     :param span: OpenTracing Span
#     :return:
#         Return context manager that wraps the request context.
#     """
# 
#     # Return a no-op Scope if None was specified.
#     if span is None:
#         return opentracing.Scope(None, None)
# 
#     return opentracing.tracer.scope_manager.activate(span, False)
# 
# Path: tests/opentracing_instrumentation/sql_common.py
# class User(object):
#     def __init__(self, name, fullname, password):


# Path: tests/opentracing_instrumentation/test_mysqldb.py
import sys
import pytest
        import MySQLdb
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import mysqldb as mysqldb_hooks
from opentracing_instrumentation.request_context import span_in_context
from .sql_common import metadata, User






SKIP_REASON_PYTHON_3 = 'MySQLdb is not compatible with Python 3'
SKIP_REASON_CONNECTION = 'MySQL is not running or cannot connect'
MYSQL_CONNECTION_STRING = 'mysql://root@127.0.0.1/test'


@pytest.fixture
def session():
    Session = sessionmaker()
    engine = create_engine(MYSQL_CONNECTION_STRING)
    Session.configure(bind=engine)
    metadata.create_all(engine)
    try:
        yield Session()
    except:
        pass


@pytest.fixture(autouse=True, scope='module')
def patch_sqlalchemy():
    mysqldb_hooks.install_patches()
    try:
        yield
    finally:

        mysqldb_hooks.reset_patches()