2323import sqlite3
2424import csv
2525import os
26- import sys
2726
2827import warnings
2928import numpy as np
3635from pandas import DataFrame , Series , Index , MultiIndex , isnull , concat
3736from pandas import date_range , to_datetime , to_timedelta , Timestamp
3837import pandas .compat as compat
39- from pandas .compat import StringIO , range , lrange , string_types , PY36
38+ from pandas .compat import range , lrange , string_types , PY36
4039from pandas .tseries .tools import format as date_format
4140
4241import pandas .io .sql as sql
@@ -2220,6 +2219,7 @@ def test_schema(self):
22202219 cur = self .conn .cursor ()
22212220 cur .execute (create_sql )
22222221
2222+ @tm .capture_stdout
22232223 def test_execute_fail (self ):
22242224 create_sql = """
22252225 CREATE TABLE test
@@ -2236,14 +2236,10 @@ def test_execute_fail(self):
22362236 sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
22372237 sql .execute ('INSERT INTO test VALUES("foo", "baz", 2.567)' , self .conn )
22382238
2239- try :
2240- sys .stdout = StringIO ()
2241- self .assertRaises (Exception , sql .execute ,
2242- 'INSERT INTO test VALUES("foo", "bar", 7)' ,
2243- self .conn )
2244- finally :
2245- sys .stdout = sys .__stdout__
2239+ with pytest .raises (Exception ):
2240+ sql .execute ('INSERT INTO test VALUES("foo", "bar", 7)' , self .conn )
22462241
2242+ @tm .capture_stdout
22472243 def test_execute_closed_connection (self ):
22482244 create_sql = """
22492245 CREATE TABLE test
@@ -2259,12 +2255,9 @@ def test_execute_closed_connection(self):
22592255
22602256 sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
22612257 self .conn .close ()
2262- try :
2263- sys .stdout = StringIO ()
2264- self .assertRaises (Exception , tquery , "select * from test" ,
2265- con = self .conn )
2266- finally :
2267- sys .stdout = sys .__stdout__
2258+
2259+ with pytest .raises (Exception ):
2260+ tquery ("select * from test" , con = self .conn )
22682261
22692262 # Initialize connection again (needed for tearDown)
22702263 self .setUp ()
@@ -2534,6 +2527,7 @@ def test_schema(self):
25342527 cur .execute (drop_sql )
25352528 cur .execute (create_sql )
25362529
2530+ @tm .capture_stdout
25372531 def test_execute_fail (self ):
25382532 _skip_if_no_pymysql ()
25392533 drop_sql = "DROP TABLE IF EXISTS test"
@@ -2553,14 +2547,10 @@ def test_execute_fail(self):
25532547 sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
25542548 sql .execute ('INSERT INTO test VALUES("foo", "baz", 2.567)' , self .conn )
25552549
2556- try :
2557- sys .stdout = StringIO ()
2558- self .assertRaises (Exception , sql .execute ,
2559- 'INSERT INTO test VALUES("foo", "bar", 7)' ,
2560- self .conn )
2561- finally :
2562- sys .stdout = sys .__stdout__
2550+ with pytest .raises (Exception ):
2551+ sql .execute ('INSERT INTO test VALUES("foo", "bar", 7)' , self .conn )
25632552
2553+ @tm .capture_stdout
25642554 def test_execute_closed_connection (self ):
25652555 _skip_if_no_pymysql ()
25662556 drop_sql = "DROP TABLE IF EXISTS test"
@@ -2579,12 +2569,9 @@ def test_execute_closed_connection(self):
25792569
25802570 sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
25812571 self .conn .close ()
2582- try :
2583- sys .stdout = StringIO ()
2584- self .assertRaises (Exception , tquery , "select * from test" ,
2585- con = self .conn )
2586- finally :
2587- sys .stdout = sys .__stdout__
2572+
2573+ with pytest .raises (Exception ):
2574+ tquery ("select * from test" , con = self .conn )
25882575
25892576 # Initialize connection again (needed for tearDown)
25902577 self .setUp ()
0 commit comments