@@ -21,7 +21,12 @@ class User(Base):
2121
2222
2323@pytest .fixture ()
24- def session ():
24+ def engine ():
25+ return create_engine ('sqlite:///:memory:' )
26+
27+
28+ @pytest .fixture ()
29+ def session (engine ):
2530 """Test Fixture to Create DataBase Tables and start a trace segment"""
2631 engine = create_engine ('sqlite:///:memory:' )
2732 xray_recorder .configure (service = 'test' , sampling = False , context = Context ())
@@ -35,6 +40,21 @@ def session():
3540 xray_recorder .clear_trace_entities ()
3641
3742
43+ @pytest .fixture ()
44+ def connection (engine ):
45+ conn = engine .connect ()
46+ xray_recorder .configure (service = 'test' , sampling = False , context = Context ())
47+ xray_recorder .clear_trace_entities ()
48+ xray_recorder .begin_segment ('SQLAlchemyTest' )
49+ Session = XRaySessionMaker (bind = conn )
50+ Base .metadata .create_all (engine )
51+ session = Session ()
52+ yield session
53+ xray_recorder .end_segment ()
54+ xray_recorder .clear_trace_entities ()
55+
56+
57+
3858def test_all (capsys , session ):
3959 """ Test calling all() on get all records.
4060 Verify we run the query and return the SQL as metdata"""
@@ -46,6 +66,14 @@ def test_all(capsys, session):
4666 assert subsegment ['sql' ]['url' ]
4767
4868
69+ def test_supports_connection (capsys , connection ):
70+ """ Test that XRaySessionMaker supports connection as well as engine"""
71+ connection .query (User ).all ()
72+ subsegment = find_subsegment_by_annotation (xray_recorder .current_segment (), 'sqlalchemy' ,
73+ 'sqlalchemy.orm.query.all' )
74+ assert subsegment ['annotations' ]['sqlalchemy' ] == 'sqlalchemy.orm.query.all'
75+
76+
4977def test_add (capsys , session ):
5078 """ Test calling add() on insert a row.
5179 Verify we that we capture trace for the add"""
0 commit comments