Skip to content

Commit

Permalink
type-ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmojaki committed Apr 28, 2024
1 parent 52d0782 commit d7eed89
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions tests/otel_integrations/test_psycopg.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,47 @@ def test_check_version():
assert not check_version('psycopg', '3.0.1', PsycopgInstrumentor())

assert check_version(psycopg.__name__, psycopg.__version__, PsycopgInstrumentor())
assert check_version(psycopg2.__name__, psycopg2.__version__, Psycopg2Instrumentor())
assert check_version(psycopg2.__name__, psycopg2.__version__, Psycopg2Instrumentor()) # type: ignore


def test_instrument_psycopg():
original_connect = psycopg.connect
original_connect = psycopg.connect # type: ignore

instrument_psycopg(psycopg)
assert original_connect is not psycopg.connect
PsycopgInstrumentor().uninstrument()
assert original_connect is psycopg.connect
assert original_connect is not psycopg.connect # type: ignore
PsycopgInstrumentor().uninstrument() # type: ignore
assert original_connect is psycopg.connect # type: ignore

instrument_psycopg('psycopg')
assert original_connect is not psycopg.connect
PsycopgInstrumentor().uninstrument()
assert original_connect is psycopg.connect
assert original_connect is not psycopg.connect # type: ignore
PsycopgInstrumentor().uninstrument() # type: ignore
assert original_connect is psycopg.connect # type: ignore


def test_instrument_psycopg2():
original_connect = psycopg2.connect

instrument_psycopg(psycopg2)
assert original_connect is not psycopg2.connect
Psycopg2Instrumentor().uninstrument()
Psycopg2Instrumentor().uninstrument() # type: ignore
assert original_connect is psycopg2.connect

instrument_psycopg('psycopg2')
assert original_connect is not psycopg2.connect
Psycopg2Instrumentor().uninstrument()
Psycopg2Instrumentor().uninstrument() # type: ignore
assert original_connect is psycopg2.connect


def test_instrument_both():
original_connect = psycopg.connect
original_connect = psycopg.connect # type: ignore
original_connect2 = psycopg2.connect

instrument_psycopg()
assert original_connect is not psycopg.connect
assert original_connect is not psycopg.connect # type: ignore
assert original_connect2 is not psycopg2.connect
PsycopgInstrumentor().uninstrument()
Psycopg2Instrumentor().uninstrument()
assert original_connect is psycopg.connect
PsycopgInstrumentor().uninstrument() # type: ignore
Psycopg2Instrumentor().uninstrument() # type: ignore
assert original_connect is psycopg.connect # type: ignore
assert original_connect2 is psycopg2.connect


Expand All @@ -69,8 +69,8 @@ def test_instrument_psycopg_connection():

instrument_psycopg(conn)
assert original_cursor_factory is not conn.cursor_factory
assert conn._is_instrumented_by_opentelemetry
PsycopgInstrumentor().uninstrument_connection(conn)
assert conn._is_instrumented_by_opentelemetry # type: ignore
PsycopgInstrumentor().uninstrument_connection(conn) # type: ignore
assert original_cursor_factory is conn.cursor_factory

pgconn.status = psycopg.pq.ConnStatus.BAD
Expand All @@ -83,7 +83,7 @@ def test_instrument_unknown():


def test_instrument_missing_otel_package():
sys.modules['opentelemetry.instrumentation.psycopg'] = None
sys.modules['opentelemetry.instrumentation.psycopg'] = None # type: ignore
with pytest.raises(
ImportError, match=r"Run `pip install 'logfire\[psycopg\]'` to install psycopg instrumentation."
):
Expand Down

0 comments on commit d7eed89

Please sign in to comment.