Skip to content

Commit 8b18d5b

Browse files
late eval of the skip condition (#2248)
* late eval of the skip condition at module import time, the REDIS_INFO dict hasn't been initialized. * Store REDIS_INFO in config object, where it is available from condition strings * Fix comparson of time You can't test rounded values for equalness, since they may fall each on a different side of 0.5. It is better to test their absolute difference for a certain tolerance, in this case 1.0 which is the intent of the original round.
1 parent 63cf7ec commit 8b18d5b

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

tests/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ def pytest_sessionstart(session):
139139
REDIS_INFO["arch_bits"] = arch_bits
140140
REDIS_INFO["cluster_enabled"] = cluster_enabled
141141
REDIS_INFO["enterprise"] = info["enterprise"]
142+
# store REDIS_INFO in config so that it is available from "condition strings"
143+
session.config.REDIS_INFO = REDIS_INFO
142144

143145
# module info, if the second redis is running
144146
try:

tests/test_asyncio/conftest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ async def _get_info(redis_url):
3939
pytest.param(
4040
(True, PythonParser),
4141
marks=pytest.mark.skipif(
42-
REDIS_INFO["cluster_enabled"], reason="cluster mode enabled"
42+
'config.REDIS_INFO["cluster_enabled"]', reason="cluster mode enabled"
4343
),
4444
),
4545
(False, PythonParser),
4646
pytest.param(
4747
(True, HiredisParser),
4848
marks=pytest.mark.skipif(
49-
not HIREDIS_AVAILABLE or REDIS_INFO["cluster_enabled"],
49+
not HIREDIS_AVAILABLE or 'config.REDIS_INFO["cluster_enabled"]',
5050
reason="hiredis is not installed or cluster mode enabled",
5151
),
5252
),

tests/test_asyncio/test_timeseries.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async def test_add(modclient: redis.Redis):
7373
4, 4, 2, retention_msecs=10, labels={"Redis": "Labs", "Time": "Series"}
7474
)
7575
res = await modclient.ts().add(5, "*", 1)
76-
assert round(time.time()) == round(float(res) / 1000)
76+
assert abs(time.time() - round(float(res) / 1000)) < 1.0
7777

7878
info = await modclient.ts().info(4)
7979
assert 10 == info.retention_msecs

tests/test_timeseries.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ def test_add(client):
7070
assert 4 == client.ts().add(
7171
4, 4, 2, retention_msecs=10, labels={"Redis": "Labs", "Time": "Series"}
7272
)
73-
assert round(time.time()) == round(float(client.ts().add(5, "*", 1)) / 1000)
73+
74+
assert abs(time.time() - float(client.ts().add(5, "*", 1)) / 1000) < 1.0
7475

7576
info = client.ts().info(4)
7677
assert 10 == info.retention_msecs

0 commit comments

Comments
 (0)