Skip to content

Commit 187a726

Browse files
Python: Fix CI on redis 6 (valkey-io#2535)
* fix tests Signed-off-by: Yury-Fridlyand <[email protected]>
1 parent 235194f commit 187a726

File tree

3 files changed

+37
-48
lines changed

3 files changed

+37
-48
lines changed

python/pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[pytest]
22
markers =
33
smoke_test: mark a test as a build verification testing.
4+
skip_if_version_below: parametrized mark for fast skipping tests by server version.
45
addopts = -k "not server_modules and not pubsub"

python/python/tests/conftest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from glide.logger import Level as logLevel
1616
from glide.logger import Logger
1717
from tests.utils.cluster import ValkeyCluster
18+
from tests.utils.utils import check_if_server_version_lt
1819

1920
DEFAULT_HOST = "localhost"
2021
DEFAULT_PORT = 6379
@@ -278,3 +279,24 @@ async def test_teardown(request, cluster_mode: bool, protocol: ProtocolVersion):
278279
client = await create_client(request, cluster_mode, protocol=protocol, timeout=2000)
279280
await client.custom_command(["FLUSHALL"])
280281
await client.close()
282+
283+
284+
@pytest.fixture(autouse=True)
285+
async def skip_if_version_below(request):
286+
"""
287+
Skip test(s) if server version is below than given parameter. Can skip a complete test suite.
288+
289+
Example:
290+
291+
@pytest.mark.skip_if_version_below('7.0.0')
292+
async def test_meow_meow(...):
293+
...
294+
"""
295+
if request.node.get_closest_marker("skip_if_version_below"):
296+
min_version = request.node.get_closest_marker("skip_if_version_below").args[0]
297+
client = await create_client(request, False)
298+
if await check_if_server_version_lt(client, min_version):
299+
pytest.skip(
300+
reason=f"This feature added in version {min_version}",
301+
allow_module_level=True,
302+
)

python/python/tests/test_pubsub.py

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ async def test_pubsub_exact_happy_path_many_channels_co_existence(
469469
await client_cleanup(listening_client, pub_sub if cluster_mode else None)
470470
await client_cleanup(publishing_client, None)
471471

472+
@pytest.mark.skip_if_version_below("7.0.0")
472473
@pytest.mark.parametrize("cluster_mode", [True])
473474
@pytest.mark.parametrize(
474475
"method", [MethodTesting.Async, MethodTesting.Sync, MethodTesting.Callback]
@@ -506,9 +507,6 @@ async def test_sharded_pubsub(
506507
listening_client, publishing_client = await create_two_clients_with_pubsub(
507508
request, cluster_mode, pub_sub
508509
)
509-
min_version = "7.0.0"
510-
if await check_if_server_version_lt(publishing_client, min_version):
511-
pytest.skip(reason=f"Valkey version required >= {min_version}")
512510

513511
assert (
514512
await cast(GlideClusterClient, publishing_client).publish(
@@ -534,6 +532,7 @@ async def test_sharded_pubsub(
534532
await client_cleanup(listening_client, pub_sub if cluster_mode else None)
535533
await client_cleanup(publishing_client, None)
536534

535+
@pytest.mark.skip_if_version_below("7.0.0")
537536
@pytest.mark.parametrize("cluster_mode", [True])
538537
async def test_sharded_pubsub_co_existence(self, request, cluster_mode: bool):
539538
"""
@@ -563,10 +562,6 @@ async def test_sharded_pubsub_co_existence(self, request, cluster_mode: bool):
563562
request, cluster_mode, pub_sub
564563
)
565564

566-
min_version = "7.0.0"
567-
if await check_if_server_version_lt(publishing_client, min_version):
568-
pytest.skip(reason=f"Valkey version required >= {min_version}")
569-
570565
assert (
571566
await cast(GlideClusterClient, publishing_client).publish(
572567
message, channel, sharded=True
@@ -608,6 +603,7 @@ async def test_sharded_pubsub_co_existence(self, request, cluster_mode: bool):
608603
await client_cleanup(listening_client, pub_sub if cluster_mode else None)
609604
await client_cleanup(publishing_client, None)
610605

606+
@pytest.mark.skip_if_version_below("7.0.0")
611607
@pytest.mark.parametrize("cluster_mode", [True])
612608
@pytest.mark.parametrize(
613609
"method", [MethodTesting.Async, MethodTesting.Sync, MethodTesting.Callback]
@@ -656,10 +652,6 @@ async def test_sharded_pubsub_many_channels(
656652
request, cluster_mode, pub_sub
657653
)
658654

659-
min_version = "7.0.0"
660-
if await check_if_server_version_lt(publishing_client, min_version):
661-
pytest.skip(reason=f"Valkey version required >= {min_version}")
662-
663655
# Publish messages to each channel
664656
for channel, message in channels_and_messages.items():
665657
assert (
@@ -1172,6 +1164,7 @@ async def test_pubsub_combined_exact_and_pattern_multiple_clients(
11721164
)
11731165
await client_cleanup(client_dont_care, None)
11741166

1167+
@pytest.mark.skip_if_version_below("7.0.0")
11751168
@pytest.mark.parametrize("cluster_mode", [True])
11761169
@pytest.mark.parametrize(
11771170
"method", [MethodTesting.Async, MethodTesting.Sync, MethodTesting.Callback]
@@ -1247,10 +1240,6 @@ async def test_pubsub_combined_exact_pattern_and_sharded_one_client(
12471240
pub_sub_exact,
12481241
)
12491242

1250-
# Setup PUBSUB for sharded channels (Valkey version > 7)
1251-
if await check_if_server_version_lt(publishing_client, "7.0.0"):
1252-
pytest.skip("Valkey version required >= 7.0.0")
1253-
12541243
# Publish messages to all channels
12551244
for channel, message in {
12561245
**exact_channels_and_messages,
@@ -1308,6 +1297,7 @@ async def test_pubsub_combined_exact_pattern_and_sharded_one_client(
13081297
)
13091298
await client_cleanup(publishing_client, None)
13101299

1300+
@pytest.mark.skip_if_version_below("7.0.0")
13111301
@pytest.mark.parametrize("cluster_mode", [True])
13121302
@pytest.mark.parametrize(
13131303
"method", [MethodTesting.Async, MethodTesting.Sync, MethodTesting.Callback]
@@ -1399,10 +1389,6 @@ async def test_pubsub_combined_exact_pattern_and_sharded_multi_client(
13991389
)
14001390
)
14011391

1402-
# Setup PUBSUB for sharded channels (Valkey version > 7)
1403-
if await check_if_server_version_lt(publishing_client, "7.0.0"):
1404-
pytest.skip("Valkey version required >= 7.0.0")
1405-
14061392
if method == MethodTesting.Callback:
14071393
context = callback_messages_pattern
14081394

@@ -1534,6 +1520,7 @@ async def test_pubsub_combined_exact_pattern_and_sharded_multi_client(
15341520
listening_client_sharded, pub_sub_sharded if cluster_mode else None
15351521
)
15361522

1523+
@pytest.mark.skip_if_version_below("7.0.0")
15371524
@pytest.mark.parametrize("cluster_mode", [True])
15381525
@pytest.mark.parametrize(
15391526
"method", [MethodTesting.Async, MethodTesting.Sync, MethodTesting.Callback]
@@ -1603,10 +1590,6 @@ async def test_pubsub_combined_different_channels_with_same_name(
16031590
)
16041591
)
16051592

1606-
# (Valkey version > 7)
1607-
if await check_if_server_version_lt(publishing_client, "7.0.0"):
1608-
pytest.skip("Valkey version required >= 7.0.0")
1609-
16101593
# Setup PUBSUB for pattern channel
16111594
if method == MethodTesting.Callback:
16121595
context = callback_messages_pattern
@@ -1801,6 +1784,7 @@ async def test_pubsub_two_publishing_clients_same_name(
18011784
client_pattern, pub_sub_pattern if cluster_mode else None
18021785
)
18031786

1787+
@pytest.mark.skip_if_version_below("7.0.0")
18041788
@pytest.mark.parametrize("cluster_mode", [True])
18051789
@pytest.mark.parametrize(
18061790
"method", [MethodTesting.Async, MethodTesting.Sync, MethodTesting.Callback]
@@ -1892,9 +1876,6 @@ async def test_pubsub_three_publishing_clients_same_name_with_sharded(
18921876
client_sharded, client_dont_care = await create_two_clients_with_pubsub(
18931877
request, cluster_mode, pub_sub_sharded
18941878
)
1895-
# (Valkey version > 7)
1896-
if await check_if_server_version_lt(client_pattern, "7.0.0"):
1897-
pytest.skip("Valkey version required >= 7.0.0")
18981879

18991880
# Publish messages to each channel - both clients publishing
19001881
assert (
@@ -2024,6 +2005,7 @@ async def test_pubsub_exact_max_size_message(self, request, cluster_mode: bool):
20242005
await client_cleanup(listening_client, pub_sub if cluster_mode else None)
20252006
await client_cleanup(publishing_client, None)
20262007

2008+
@pytest.mark.skip_if_version_below("7.0.0")
20272009
@pytest.mark.skip(
20282010
reason="This test requires special configuration for client-output-buffer-limit for valkey-server and timeouts seems to vary across platforms and server versions"
20292011
)
@@ -2062,10 +2044,6 @@ async def test_pubsub_sharded_max_size_message(self, request, cluster_mode: bool
20622044
timeout=10000,
20632045
)
20642046

2065-
# (Valkey version > 7)
2066-
if await check_if_server_version_lt(publishing_client, "7.0.0"):
2067-
pytest.skip("Valkey version required >= 7.0.0")
2068-
20692047
assert (
20702048
await cast(GlideClusterClient, publishing_client).publish(
20712049
message, channel, sharded=True
@@ -2161,6 +2139,7 @@ async def test_pubsub_exact_max_size_message_callback(
21612139
await client_cleanup(listening_client, pub_sub if cluster_mode else None)
21622140
await client_cleanup(publishing_client, None)
21632141

2142+
@pytest.mark.skip_if_version_below("7.0.0")
21642143
@pytest.mark.skip(
21652144
reason="This test requires special configuration for client-output-buffer-limit for valkey-server and timeouts seems to vary across platforms and server versions"
21662145
)
@@ -2201,10 +2180,6 @@ async def test_pubsub_sharded_max_size_message_callback(
22012180
request, cluster_mode, pub_sub, timeout=10000
22022181
)
22032182

2204-
# (Valkey version > 7)
2205-
if await check_if_server_version_lt(publishing_client, "7.0.0"):
2206-
pytest.skip("Valkey version required >= 7.0.0")
2207-
22082183
assert (
22092184
await cast(GlideClusterClient, publishing_client).publish(
22102185
message, channel, sharded=True
@@ -2463,6 +2438,7 @@ async def test_pubsub_numsub(self, request, cluster_mode: bool):
24632438
await client_cleanup(client4, None)
24642439
await client_cleanup(client, None)
24652440

2441+
@pytest.mark.skip_if_version_below("7.0.0")
24662442
@pytest.mark.parametrize("cluster_mode", [True])
24672443
async def test_pubsub_shardchannels(self, request, cluster_mode: bool):
24682444
"""
@@ -2479,9 +2455,6 @@ async def test_pubsub_shardchannels(self, request, cluster_mode: bool):
24792455
pattern = "test_*"
24802456

24812457
client = await create_client(request, cluster_mode)
2482-
min_version = "7.0.0"
2483-
if await check_if_server_version_lt(client, min_version):
2484-
pytest.skip(reason=f"Valkey version required >= {min_version}")
24852458
assert type(client) == GlideClusterClient
24862459
# Assert no sharded channels exist yet
24872460
assert await client.pubsub_shardchannels() == []
@@ -2524,6 +2497,7 @@ async def test_pubsub_shardchannels(self, request, cluster_mode: bool):
25242497
await client_cleanup(client2, None)
25252498
await client_cleanup(client, None)
25262499

2500+
@pytest.mark.skip_if_version_below("7.0.0")
25272501
@pytest.mark.parametrize("cluster_mode", [True])
25282502
async def test_pubsub_shardnumsub(self, request, cluster_mode: bool):
25292503
"""
@@ -2578,9 +2552,7 @@ async def test_pubsub_shardnumsub(self, request, cluster_mode: bool):
25782552

25792553
# Create a client and check initial subscribers
25802554
client = await create_client(request, cluster_mode)
2581-
min_version = "7.0.0"
2582-
if await check_if_server_version_lt(client, min_version):
2583-
pytest.skip(reason=f"Valkey version required >= {min_version}")
2555+
25842556
assert type(client) == GlideClusterClient
25852557
assert await client.pubsub_shardnumsub([channel1, channel2, channel3]) == {
25862558
channel1_bytes: 0,
@@ -2620,6 +2592,7 @@ async def test_pubsub_shardnumsub(self, request, cluster_mode: bool):
26202592
await client_cleanup(client4, None)
26212593
await client_cleanup(client, None)
26222594

2595+
@pytest.mark.skip_if_version_below("7.0.0")
26232596
@pytest.mark.parametrize("cluster_mode", [True])
26242597
async def test_pubsub_channels_and_shardchannels_separation(
26252598
self, request, cluster_mode: bool
@@ -2655,10 +2628,6 @@ async def test_pubsub_channels_and_shardchannels_separation(
26552628
request, cluster_mode, pub_sub
26562629
)
26572630

2658-
min_version = "7.0.0"
2659-
if await check_if_server_version_lt(client1, min_version):
2660-
pytest.skip(reason=f"Valkey version required >= {min_version}")
2661-
26622631
assert type(client2) == GlideClusterClient
26632632
# Test pubsub_channels
26642633
assert await client2.pubsub_channels() == [regular_channel_bytes]
@@ -2670,6 +2639,7 @@ async def test_pubsub_channels_and_shardchannels_separation(
26702639
await client_cleanup(client1, pub_sub if cluster_mode else None)
26712640
await client_cleanup(client2, None)
26722641

2642+
@pytest.mark.skip_if_version_below("7.0.0")
26732643
@pytest.mark.parametrize("cluster_mode", [True])
26742644
async def test_pubsub_numsub_and_shardnumsub_separation(
26752645
self, request, cluster_mode: bool
@@ -2715,10 +2685,6 @@ async def test_pubsub_numsub_and_shardnumsub_separation(
27152685
request, cluster_mode, pub_sub1, pub_sub2
27162686
)
27172687

2718-
min_version = "7.0.0"
2719-
if await check_if_server_version_lt(client1, min_version):
2720-
pytest.skip(reason=f"Valkey version required >= {min_version}")
2721-
27222688
assert type(client2) == GlideClusterClient
27232689

27242690
# Test pubsub_numsub

0 commit comments

Comments
 (0)