66import threading
77import logging
88from queue import Queue
9- import distutils .version
109
1110import six
11+ from packaging .version import Version
1212import pytest
1313import redis
1414import redis .client
1717from datetime import datetime , timedelta
1818
1919
20- REDIS_VERSION = distutils . version . LooseVersion (redis .__version__ )
21- REDIS3 = REDIS_VERSION >= '3'
20+ REDIS_VERSION = Version (redis .__version__ )
21+ REDIS3 = REDIS_VERSION >= Version ( '3' )
2222
2323
2424redis2_only = pytest .mark .skipif (REDIS3 , reason = "Test is only applicable to redis-py 2.x" )
@@ -99,8 +99,8 @@ def factory(db=0):
9999 min_server_marker = request .node .get_closest_marker ('min_server' )
100100 if min_server_marker is not None :
101101 server_version = conn .info ()['redis_version' ]
102- min_version = min_server_marker .args [0 ]
103- if distutils . version . LooseVersion (server_version ) < min_version :
102+ min_version = Version ( min_server_marker .args [0 ])
103+ if Version (server_version ) < min_version :
104104 pytest .skip (
105105 'Redis server {} required but {} found' .format (min_version , server_version )
106106 )
@@ -729,7 +729,7 @@ def test_set_px_using_timedelta(r):
729729 assert r .get ('foo' ) == b'bar'
730730
731731
732- @pytest .mark .skipif (REDIS_VERSION < '3.5' , reason = "Test is only applicable to redis-py 3.5+" )
732+ @pytest .mark .skipif (REDIS_VERSION < Version ( '3.5' ) , reason = "Test is only applicable to redis-py 3.5+" )
733733@pytest .mark .min_server ('6.0' )
734734def test_set_keepttl (r ):
735735 r .set ('foo' , 'bar' , ex = 100 )
@@ -743,7 +743,7 @@ def test_set_conflicting_expire_options(r):
743743 r .set ('foo' , 'bar' , ex = 1 , px = 1 )
744744
745745
746- @pytest .mark .skipif (REDIS_VERSION < '3.5' , reason = "Test is only applicable to redis-py 3.5+" )
746+ @pytest .mark .skipif (REDIS_VERSION < Version ( '3.5' ) , reason = "Test is only applicable to redis-py 3.5+" )
747747def test_set_conflicting_expire_options_w_keepttl (r ):
748748 with pytest .raises (ResponseError ):
749749 r .set ('foo' , 'bar' , ex = 1 , keepttl = True )
@@ -1682,7 +1682,7 @@ def test_scan_iter_multiple_pages_with_match(r):
16821682 assert actual == set (all_keys )
16831683
16841684
1685- @pytest .mark .skipif (REDIS_VERSION < '3.5' , reason = "Test is only applicable to redis-py 3.5+" )
1685+ @pytest .mark .skipif (REDIS_VERSION < Version ( '3.5' ) , reason = "Test is only applicable to redis-py 3.5+" )
16861686@pytest .mark .min_server ('6.0' )
16871687def test_scan_iter_multiple_pages_with_type (r ):
16881688 all_keys = key_val_dict (size = 100 )
@@ -2101,7 +2101,7 @@ def test_zadd_with_nx_and_xx(r, ch):
21012101 zadd (r , 'foo' , {'four' : - 4.0 , 'three' : - 3.0 }, nx = True , xx = True , ch = ch )
21022102
21032103
2104- @pytest .mark .skipif (REDIS_VERSION < '3.1' , reason = "Test is only applicable to redis-py 3.1+" )
2104+ @pytest .mark .skipif (REDIS_VERSION < Version ( '3.1' ) , reason = "Test is only applicable to redis-py 3.1+" )
21052105@pytest .mark .parametrize ('ch' , [False , True ])
21062106def test_zadd_incr (r , ch ):
21072107 zadd (r , 'foo' , {'four' : 4.0 , 'three' : 3.0 })
@@ -3335,7 +3335,7 @@ def test_pipeline_no_commands(r):
33353335 p = r .pipeline ()
33363336 p .watch ('foo' )
33373337 r .set ('foo' , '2' )
3338- if REDIS_VERSION >= '3.4' :
3338+ if REDIS_VERSION >= Version ( '3.4' ) :
33393339 with pytest .raises (redis .WatchError ):
33403340 p .execute ()
33413341 else :
@@ -3781,7 +3781,7 @@ def test_pubsub_run_in_thread(r):
37813781 pytest .param (
37823782 None ,
37833783 marks = pytest .mark .skipif (
3784- REDIS_VERSION >= "3.2" and REDIS_VERSION < "3.3" ,
3784+ Version ( "3.2" ) <= REDIS_VERSION < Version ( "3.3" ) ,
37853785 reason = "This test is not applicable to redis-py 3.2"
37863786 )
37873787 )
@@ -4694,7 +4694,7 @@ def test_unlink(r):
46944694 assert r .get ('foo' ) is None
46954695
46964696
4697- @pytest .mark .skipif (REDIS_VERSION < "3.4" , reason = "Test requires redis-py 3.4+" )
4697+ @pytest .mark .skipif (REDIS_VERSION < Version ( "3.4" ) , reason = "Test requires redis-py 3.4+" )
46984698@pytest .mark .fake
46994699def test_socket_cleanup_pubsub (fake_server ):
47004700 r1 = fakeredis .FakeStrictRedis (server = fake_server )
0 commit comments