1
1
import datetime
2
2
import sys
3
3
import time
4
- import unittest2
4
+ import pytest
5
5
import pymysql
6
6
from pymysql .tests import base
7
7
from pymysql ._compat import text_type
@@ -100,14 +100,14 @@ class TestAuthentication(base.PyMySQLTestCase):
100
100
def test_plugin (self ):
101
101
conn = self .connect ()
102
102
if not self .mysql_server_is (conn , (5 , 5 , 0 )):
103
- raise unittest2 . SkipTest ("MySQL-5.5 required for plugins" )
103
+ pytest . skip ("MySQL-5.5 required for plugins" )
104
104
cur = conn .cursor ()
105
105
cur .execute ("select plugin from mysql.user where concat(user, '@', host)=current_user()" )
106
106
for r in cur :
107
107
self .assertIn (conn ._auth_plugin_name , (r [0 ], 'mysql_native_password' ))
108
108
109
- @unittest2 . skipUnless ( socket_auth , "connection to unix_socket required" )
110
- @unittest2 . skipIf (socket_found , "socket plugin already installed" )
109
+ @pytest . mark . skipif ( not socket_auth , reason = "connection to unix_socket required" )
110
+ @pytest . mark . skipif (socket_found , reason = "socket plugin already installed" )
111
111
def testSocketAuthInstallPlugin (self ):
112
112
# needs plugin. lets install it.
113
113
cur = self .connect ().cursor ()
@@ -124,13 +124,13 @@ def testSocketAuthInstallPlugin(self):
124
124
self .realtestSocketAuth ()
125
125
except pymysql .err .InternalError :
126
126
TestAuthentication .socket_found = False
127
- raise unittest2 . SkipTest ('we couldn\' t install the socket plugin' )
127
+ pytest . skip ('we couldn\' t install the socket plugin' )
128
128
finally :
129
129
if TestAuthentication .socket_found :
130
130
cur .execute ("uninstall plugin %s" % self .socket_plugin_name )
131
131
132
- @unittest2 . skipUnless ( socket_auth , "connection to unix_socket required" )
133
- @unittest2 . skipUnless ( socket_found , "no socket plugin" )
132
+ @pytest . mark . skipif ( not socket_auth , reason = "connection to unix_socket required" )
133
+ @pytest . mark . skipif ( not socket_found , reason = "no socket plugin" )
134
134
def testSocketAuth (self ):
135
135
self .realtestSocketAuth ()
136
136
@@ -179,8 +179,8 @@ def __init__(self, con):
179
179
self .con = con
180
180
181
181
182
- @unittest2 . skipUnless ( socket_auth , "connection to unix_socket required" )
183
- @unittest2 . skipIf (two_questions_found , "two_questions plugin already installed" )
182
+ @pytest . mark . skipif ( not socket_auth , reason = "connection to unix_socket required" )
183
+ @pytest . mark . skipif (two_questions_found , reason = "two_questions plugin already installed" )
184
184
def testDialogAuthTwoQuestionsInstallPlugin (self ):
185
185
# needs plugin. lets install it.
186
186
cur = self .connect ().cursor ()
@@ -189,13 +189,13 @@ def testDialogAuthTwoQuestionsInstallPlugin(self):
189
189
TestAuthentication .two_questions_found = True
190
190
self .realTestDialogAuthTwoQuestions ()
191
191
except pymysql .err .InternalError :
192
- raise unittest2 . SkipTest ('we couldn\' t install the two_questions plugin' )
192
+ pytest . skip ('we couldn\' t install the two_questions plugin' )
193
193
finally :
194
194
if TestAuthentication .two_questions_found :
195
195
cur .execute ("uninstall plugin two_questions" )
196
196
197
- @unittest2 . skipUnless ( socket_auth , "connection to unix_socket required" )
198
- @unittest2 . skipUnless ( two_questions_found , "no two questions auth plugin" )
197
+ @pytest . mark . skipif ( not socket_auth , reason = "connection to unix_socket required" )
198
+ @pytest . mark . skipif ( not two_questions_found , reason = "no two questions auth plugin" )
199
199
def testDialogAuthTwoQuestions (self ):
200
200
self .realTestDialogAuthTwoQuestions ()
201
201
@@ -209,8 +209,8 @@ def realTestDialogAuthTwoQuestions(self):
209
209
pymysql .connect (user = 'pymysql_2q' , ** self .db )
210
210
pymysql .connect (user = 'pymysql_2q' , auth_plugin_map = {b'dialog' : TestAuthentication .Dialog }, ** self .db )
211
211
212
- @unittest2 . skipUnless ( socket_auth , "connection to unix_socket required" )
213
- @unittest2 . skipIf (three_attempts_found , "three_attempts plugin already installed" )
212
+ @pytest . mark . skipif ( not socket_auth , reason = "connection to unix_socket required" )
213
+ @pytest . mark . skipif (three_attempts_found , reason = "three_attempts plugin already installed" )
214
214
def testDialogAuthThreeAttemptsQuestionsInstallPlugin (self ):
215
215
# needs plugin. lets install it.
216
216
cur = self .connect ().cursor ()
@@ -219,13 +219,13 @@ def testDialogAuthThreeAttemptsQuestionsInstallPlugin(self):
219
219
TestAuthentication .three_attempts_found = True
220
220
self .realTestDialogAuthThreeAttempts ()
221
221
except pymysql .err .InternalError :
222
- raise unittest2 . SkipTest ('we couldn\' t install the three_attempts plugin' )
222
+ pytest . skip ('we couldn\' t install the three_attempts plugin' )
223
223
finally :
224
224
if TestAuthentication .three_attempts_found :
225
225
cur .execute ("uninstall plugin three_attempts" )
226
226
227
- @unittest2 . skipUnless ( socket_auth , "connection to unix_socket required" )
228
- @unittest2 . skipUnless ( three_attempts_found , "no three attempts plugin" )
227
+ @pytest . mark . skipif ( not socket_auth , reason = "connection to unix_socket required" )
228
+ @pytest . mark . skipif ( not three_attempts_found , reason = "no three attempts plugin" )
229
229
def testDialogAuthThreeAttempts (self ):
230
230
self .realTestDialogAuthThreeAttempts ()
231
231
@@ -250,10 +250,10 @@ def realTestDialogAuthThreeAttempts(self):
250
250
with self .assertRaises (pymysql .err .OperationalError ):
251
251
pymysql .connect (user = 'pymysql_3a' , auth_plugin_map = {b'dialog' : TestAuthentication .Dialog }, ** self .db )
252
252
253
- @unittest2 . skipUnless ( socket_auth , "connection to unix_socket required" )
254
- @unittest2 . skipIf (pam_found , "pam plugin already installed" )
255
- @unittest2 . skipIf (os .environ .get ('PASSWORD' ) is None , "PASSWORD env var required" )
256
- @unittest2 . skipIf (os .environ .get ('PAMSERVICE' ) is None , "PAMSERVICE env var required" )
253
+ @pytest . mark . skipif ( not socket_auth , reason = "connection to unix_socket required" )
254
+ @pytest . mark . skipif (pam_found , reason = "pam plugin already installed" )
255
+ @pytest . mark . skipif (os .environ .get ('PASSWORD' ) is None , reason = "PASSWORD env var required" )
256
+ @pytest . mark . skipif (os .environ .get ('PAMSERVICE' ) is None , reason = "PAMSERVICE env var required" )
257
257
def testPamAuthInstallPlugin (self ):
258
258
# needs plugin. lets install it.
259
259
cur = self .connect ().cursor ()
@@ -262,16 +262,16 @@ def testPamAuthInstallPlugin(self):
262
262
TestAuthentication .pam_found = True
263
263
self .realTestPamAuth ()
264
264
except pymysql .err .InternalError :
265
- raise unittest2 . SkipTest ('we couldn\' t install the auth_pam plugin' )
265
+ pytest . skip ('we couldn\' t install the auth_pam plugin' )
266
266
finally :
267
267
if TestAuthentication .pam_found :
268
268
cur .execute ("uninstall plugin pam" )
269
269
270
270
271
- @unittest2 . skipUnless ( socket_auth , "connection to unix_socket required" )
272
- @unittest2 . skipUnless ( pam_found , "no pam plugin" )
273
- @unittest2 . skipIf (os .environ .get ('PASSWORD' ) is None , "PASSWORD env var required" )
274
- @unittest2 . skipIf (os .environ .get ('PAMSERVICE' ) is None , "PAMSERVICE env var required" )
271
+ @pytest . mark . skipif ( not socket_auth , reason = "connection to unix_socket required" )
272
+ @pytest . mark . skipif ( not pam_found , reason = "no pam plugin" )
273
+ @pytest . mark . skipif (os .environ .get ('PASSWORD' ) is None , reason = "PASSWORD env var required" )
274
+ @pytest . mark . skipif (os .environ .get ('PAMSERVICE' ) is None , reason = "PAMSERVICE env var required" )
275
275
def testPamAuth (self ):
276
276
self .realTestPamAuth ()
277
277
@@ -311,16 +311,16 @@ def realTestPamAuth(self):
311
311
# select old_password("crummy p\tassword");
312
312
#| old_password("crummy p\tassword") |
313
313
#| 2a01785203b08770 |
314
- @unittest2 . skipUnless ( socket_auth , "connection to unix_socket required" )
315
- @unittest2 . skipUnless ( mysql_old_password_found , "no mysql_old_password plugin" )
314
+ @pytest . mark . skipif ( not socket_auth , reason = "connection to unix_socket required" )
315
+ @pytest . mark . skipif ( not mysql_old_password_found , reason = "no mysql_old_password plugin" )
316
316
def testMySQLOldPasswordAuth (self ):
317
317
conn = self .connect ()
318
318
if self .mysql_server_is (conn , (5 , 7 , 0 )):
319
- raise unittest2 . SkipTest ('Old passwords aren\' t supported in 5.7' )
319
+ pytest . skip ('Old passwords aren\' t supported in 5.7' )
320
320
# pymysql.err.OperationalError: (1045, "Access denied for user 'old_pass_user'@'localhost' (using password: YES)")
321
321
# from login in MySQL-5.6
322
322
if self .mysql_server_is (conn , (5 , 6 , 0 )):
323
- raise unittest2 . SkipTest ('Old passwords don\' t authenticate in 5.6' )
323
+ pytest . skip ('Old passwords don\' t authenticate in 5.6' )
324
324
db = self .db .copy ()
325
325
db ['password' ] = "crummy p\t assword"
326
326
c = conn .cursor ()
@@ -354,8 +354,8 @@ def testMySQLOldPasswordAuth(self):
354
354
cur .execute ("SELECT VERSION()" )
355
355
c .execute ('set global secure_auth=%r' % secure_auth_setting )
356
356
357
- @unittest2 . skipUnless ( socket_auth , "connection to unix_socket required" )
358
- @unittest2 . skipUnless ( sha256_password_found , "no sha256 password authentication plugin found" )
357
+ @pytest . mark . skipif ( not socket_auth , reason = "connection to unix_socket required" )
358
+ @pytest . mark . skipif ( not sha256_password_found , reason = "no sha256 password authentication plugin found" )
359
359
def testAuthSHA256 (self ):
360
360
conn = self .connect ()
361
361
c = conn .cursor ()
0 commit comments