11import unittest
22
3+ import pytest
4+
35import pymssql as pym
46
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 )
79
810class TestDBAPI2 (object ):
911 def test_version (self ):
@@ -160,10 +162,11 @@ def test_db_creation_with_autocommit(self):
160162 try :
161163 cur .execute ("CREATE DATABASE {0}" .format (self .test_db_name ))
162164 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 ]):
164167 skip_test ('We have no CREATE DATABASE permission on test database' )
165168 else :
166- raise
169+ pytest . fail ()
167170 else :
168171 cur .execute ("DROP DATABASE {0}" .format (self .test_db_name ))
169172
@@ -172,12 +175,10 @@ def test_db_creation_without_autocommit(self):
172175 Try creating and dropping database without autocommit, expecting it to fail
173176 """
174177 cur = pymssqlconn (autocommit = False ).cursor ()
175- try :
178+ with pytest . raises ( pym . OperationalError ) as excinfo :
176179 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 ()
181182
182183 def test_autocommit_flipping_tf (self ):
183184 insert_value = 'true-false'
0 commit comments