1818from tests .contrib .config import MYSQL_CONFIG
1919
2020from mysql .connector import __version__ as connector_version
21- from subprocess import call
21+ from subprocess import check_call
2222
2323META_KEY = "this.is"
2424META_VALUE = "A simple test value"
@@ -83,7 +83,7 @@ def tearDown():
8383def test_version ():
8484 """Print client version"""
8585 # trick to bypass nose output capture -> spawn a subprocess
86- call (["echo" , "\n mysql.connector.__version__: %s" % str (connector_version )])
86+ check_call (["echo" , "\n mysql.connector.__version__: %s" % str (connector_version )])
8787
8888def test_connection ():
8989 """Tests that a connection can be opened."""
@@ -190,7 +190,9 @@ def test_query_with_several_rows():
190190 cursor .execute (query )
191191 rows = cursor .fetchall ()
192192 eq_ (len (rows ), 3 )
193+
193194 spans = writer .pop ()
195+ assert_greater_equal (len (spans ), 1 )
194196 for span in spans :
195197 assert_dict_contains_subset ({'sql.query' : query }, span .meta )
196198
@@ -204,25 +206,27 @@ def test_query_many():
204206 conn = MySQL (** MYSQL_CONFIG )
205207 cursor = conn .cursor ()
206208 cursor .execute (CREATE_TABLE_DUMMY )
209+
207210 stmt = "INSERT INTO dummy (dummy_key,dummy_value) VALUES (%s, %s)"
208211 data = [("foo" ,"this is foo" ),
209212 ("bar" ,"this is bar" )]
210213 cursor .executemany (stmt , data )
211- cursor .execute ("SELECT dummy_key, dummy_value FROM dummy "
212- "ORDER BY dummy_key" )
214+ query = "SELECT dummy_key, dummy_value FROM dummy " \
215+ "ORDER BY dummy_key"
216+ cursor .execute (query )
213217 rows = cursor .fetchall ()
214218 eq_ (len (rows ), 2 )
215219 eq_ (rows [0 ][0 ], "bar" )
216220 eq_ (rows [0 ][1 ], "this is bar" )
217221 eq_ (rows [1 ][0 ], "foo" )
218222 eq_ (rows [1 ][1 ], "this is foo" )
219223
220- cursor .execute (DROP_TABLE_DUMMY )
221-
222224 spans = writer .pop ()
223- assert_greater_equal (len (spans ), 3 )
224- span = spans [2 ]
225- assert_dict_contains_subset ({'sql.query' : stmt }, span .meta )
225+ assert_greater_equal (len (spans ), 2 )
226+ span = spans [- 1 ]
227+ assert_dict_contains_subset ({'sql.query' : query }, span .meta )
228+
229+ cursor .execute (DROP_TABLE_DUMMY )
226230
227231def test_query_proc ():
228232 """Tests that callproc works as expected, and generates a correct span."""
@@ -287,7 +291,6 @@ def test_fetch_variants():
287291 query = "SELECT dummy_key, dummy_value FROM dummy " \
288292 "ORDER BY dummy_key"
289293 cursor .execute (query )
290- writer .pop () # flushing traces
291294
292295 rows = cursor .fetchmany (size = NB_FETCH_MANY )
293296 fetchmany_rowcount_a = cursor .rowcount
@@ -320,8 +323,9 @@ def test_fetch_variants():
320323 eq_ (NB_FETCH_TOTAL , fetchmany_nbrows_a + fetchmany_nbrows_b + 2 )
321324
322325 spans = writer .pop ()
323- for span in spans :
324- assert_dict_contains_subset ({'sql.query' : query }, span .meta )
326+ assert_greater_equal (len (spans ), 1 )
327+ span = spans [- 1 ]
328+ assert_dict_contains_subset ({'sql.query' : query }, span .meta )
325329
326330 cursor .execute (DROP_TABLE_DUMMY )
327331
@@ -339,7 +343,9 @@ def check_connection_class(buffered, raw, baseclass_name):
339343 rows = cursor .fetchall ()
340344 eq_ (len (rows ), 1 )
341345 eq_ (int (rows [0 ][0 ]), 1 )
346+
342347 spans = writer .pop ()
348+ assert_greater_equal (len (spans ), 1 )
343349 for span in spans :
344350 assert_dict_contains_subset ({'sql.query' : query }, span .meta )
345351
@@ -371,7 +377,9 @@ def check_cursor_class(buffered, raw, baseclass_name):
371377 rows = cursor .fetchall ()
372378 eq_ (len (rows ), 1 )
373379 eq_ (int (rows [0 ][0 ]), 1 )
380+
374381 spans = writer .pop ()
382+ assert_greater_equal (len (spans ), 1 )
375383 for span in spans :
376384 assert_dict_contains_subset ({'sql.query' : query }, span .meta )
377385
0 commit comments