コード例 #1
0
    def test_patch_unpatch(self):
        unpatch()
        # assert we start unpatched
        conn = pyodbc.connect(PYODBC_CONNECT_DSN)
        assert not Pin.get_from(conn)
        conn.close()

        patch()
        try:
            conn = pyodbc.connect(PYODBC_CONNECT_DSN)
            pin = Pin.get_from(conn)
            assert pin
            pin.clone(tracer=self.tracer).onto(conn)

            cursor = conn.cursor()
            cursor.execute("SELECT 1")
            rows = cursor.fetchall()
            assert len(rows) == 1
            spans = self.pop_spans()
            assert len(spans) == 1

            span = spans[0]
            assert span.service == "pyodbc"
            assert span.name == "pyodbc.query"
            assert span.span_type == "sql"
            assert span.error == 0
        finally:
            unpatch()

            # assert we finish unpatched
            conn = pyodbc.connect(PYODBC_CONNECT_DSN)
            assert not Pin.get_from(conn)
            conn.close()

        patch()
コード例 #2
0
 def tearDown(self):
     super(PyODBCTest, self).tearDown()
     if self.conn:
         try:
             self.conn.close()
         except pyodbc.ProgrammingError:
             pass
     unpatch()