1
1
import unittest
2
2
3
+ import pytest
4
+
3
5
import pymssql as pym
4
6
5
- from .helpers import (pymssqlconn , PyTableBase , drop_table , CursorBase , eq_ ,
6
- config , skip_test )
7
+ from .helpers import (pymssqlconn , PyTableBase , CursorBase , eq_ , config ,
8
+ skip_test )
7
9
8
10
class TestDBAPI2 (object ):
9
11
def test_version (self ):
@@ -160,10 +162,11 @@ def test_db_creation_with_autocommit(self):
160
162
try :
161
163
cur .execute ("CREATE DATABASE {0}" .format (self .test_db_name ))
162
164
except pym .OperationalError as e :
163
- if "CREATE DATABASE permission denied in database 'master'" in e .args [1 ]:
165
+ expected_msg = "CREATE DATABASE permission denied in database 'master'"
166
+ if expected_msg in str (e .args [1 ]):
164
167
skip_test ('We have no CREATE DATABASE permission on test database' )
165
168
else :
166
- raise
169
+ pytest . fail ()
167
170
else :
168
171
cur .execute ("DROP DATABASE {0}" .format (self .test_db_name ))
169
172
@@ -172,12 +175,10 @@ def test_db_creation_without_autocommit(self):
172
175
Try creating and dropping database without autocommit, expecting it to fail
173
176
"""
174
177
cur = pymssqlconn (autocommit = False ).cursor ()
175
- try :
178
+ with pytest . raises ( pym . OperationalError ) as excinfo :
176
179
cur .execute ("CREATE DATABASE autocommit_test_database" )
177
- except pym .OperationalError as e :
178
- assert "CREATE DATABASE statement not allowed within multi-statement transaction" in e .args [1 ]
179
- else :
180
- assert False
180
+ expected_msg = "CREATE DATABASE statement not allowed within multi-statement transaction"
181
+ assert expected_msg in excinfo .exconly ()
181
182
182
183
def test_autocommit_flipping_tf (self ):
183
184
insert_value = 'true-false'
0 commit comments