23
23
import sqlite3
24
24
import csv
25
25
import os
26
- import sys
27
26
28
27
import warnings
29
28
import numpy as np
36
35
from pandas import DataFrame , Series , Index , MultiIndex , isnull , concat
37
36
from pandas import date_range , to_datetime , to_timedelta , Timestamp
38
37
import 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
40
39
from pandas .tseries .tools import format as date_format
41
40
42
41
import pandas .io .sql as sql
@@ -2220,6 +2219,7 @@ def test_schema(self):
2220
2219
cur = self .conn .cursor ()
2221
2220
cur .execute (create_sql )
2222
2221
2222
+ @tm .capture_stdout
2223
2223
def test_execute_fail (self ):
2224
2224
create_sql = """
2225
2225
CREATE TABLE test
@@ -2236,14 +2236,10 @@ def test_execute_fail(self):
2236
2236
sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
2237
2237
sql .execute ('INSERT INTO test VALUES("foo", "baz", 2.567)' , self .conn )
2238
2238
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 )
2246
2241
2242
+ @tm .capture_stdout
2247
2243
def test_execute_closed_connection (self ):
2248
2244
create_sql = """
2249
2245
CREATE TABLE test
@@ -2259,12 +2255,9 @@ def test_execute_closed_connection(self):
2259
2255
2260
2256
sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
2261
2257
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 )
2268
2261
2269
2262
# Initialize connection again (needed for tearDown)
2270
2263
self .setUp ()
@@ -2534,6 +2527,7 @@ def test_schema(self):
2534
2527
cur .execute (drop_sql )
2535
2528
cur .execute (create_sql )
2536
2529
2530
+ @tm .capture_stdout
2537
2531
def test_execute_fail (self ):
2538
2532
_skip_if_no_pymysql ()
2539
2533
drop_sql = "DROP TABLE IF EXISTS test"
@@ -2553,14 +2547,10 @@ def test_execute_fail(self):
2553
2547
sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
2554
2548
sql .execute ('INSERT INTO test VALUES("foo", "baz", 2.567)' , self .conn )
2555
2549
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 )
2563
2552
2553
+ @tm .capture_stdout
2564
2554
def test_execute_closed_connection (self ):
2565
2555
_skip_if_no_pymysql ()
2566
2556
drop_sql = "DROP TABLE IF EXISTS test"
@@ -2579,12 +2569,9 @@ def test_execute_closed_connection(self):
2579
2569
2580
2570
sql .execute ('INSERT INTO test VALUES("foo", "bar", 1.234)' , self .conn )
2581
2571
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 )
2588
2575
2589
2576
# Initialize connection again (needed for tearDown)
2590
2577
self .setUp ()
0 commit comments