summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristján Valur Jónsson <sweskman@gmail.com>2022-06-27 09:11:13 +0000
committerGitHub <noreply@github.com>2022-06-27 12:11:13 +0300
commit8b18d5b2b63ebf218a1f116367a1a09c3d402192 (patch)
tree6409d4ed971b431a73ca3efe4c10104177af577d
parent63cf7ec5cbaca533b7607196dbf993917a65c0f9 (diff)
downloadredis-py-8b18d5b2b63ebf218a1f116367a1a09c3d402192.tar.gz
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.
-rw-r--r--tests/conftest.py2
-rw-r--r--tests/test_asyncio/conftest.py4
-rw-r--r--tests/test_asyncio/test_timeseries.py2
-rw-r--r--tests/test_timeseries.py3
4 files changed, 7 insertions, 4 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index e83c866..8a907cc 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -139,6 +139,8 @@ def pytest_sessionstart(session):
REDIS_INFO["arch_bits"] = arch_bits
REDIS_INFO["cluster_enabled"] = cluster_enabled
REDIS_INFO["enterprise"] = info["enterprise"]
+ # store REDIS_INFO in config so that it is available from "condition strings"
+ session.config.REDIS_INFO = REDIS_INFO
# module info, if the second redis is running
try:
diff --git a/tests/test_asyncio/conftest.py b/tests/test_asyncio/conftest.py
index b8b5583..52ff26b 100644
--- a/tests/test_asyncio/conftest.py
+++ b/tests/test_asyncio/conftest.py
@@ -39,14 +39,14 @@ async def _get_info(redis_url):
pytest.param(
(True, PythonParser),
marks=pytest.mark.skipif(
- REDIS_INFO["cluster_enabled"], reason="cluster mode enabled"
+ 'config.REDIS_INFO["cluster_enabled"]', reason="cluster mode enabled"
),
),
(False, PythonParser),
pytest.param(
(True, HiredisParser),
marks=pytest.mark.skipif(
- not HIREDIS_AVAILABLE or REDIS_INFO["cluster_enabled"],
+ not HIREDIS_AVAILABLE or 'config.REDIS_INFO["cluster_enabled"]',
reason="hiredis is not installed or cluster mode enabled",
),
),
diff --git a/tests/test_asyncio/test_timeseries.py b/tests/test_asyncio/test_timeseries.py
index 70ca6fd..ac2807f 100644
--- a/tests/test_asyncio/test_timeseries.py
+++ b/tests/test_asyncio/test_timeseries.py
@@ -73,7 +73,7 @@ async def test_add(modclient: redis.Redis):
4, 4, 2, retention_msecs=10, labels={"Redis": "Labs", "Time": "Series"}
)
res = await modclient.ts().add(5, "*", 1)
- assert round(time.time()) == round(float(res) / 1000)
+ assert abs(time.time() - round(float(res) / 1000)) < 1.0
info = await modclient.ts().info(4)
assert 10 == info.retention_msecs
diff --git a/tests/test_timeseries.py b/tests/test_timeseries.py
index 421c9d5..7d42147 100644
--- a/tests/test_timeseries.py
+++ b/tests/test_timeseries.py
@@ -70,7 +70,8 @@ def test_add(client):
assert 4 == client.ts().add(
4, 4, 2, retention_msecs=10, labels={"Redis": "Labs", "Time": "Series"}
)
- assert round(time.time()) == round(float(client.ts().add(5, "*", 1)) / 1000)
+
+ assert abs(time.time() - float(client.ts().add(5, "*", 1)) / 1000) < 1.0
info = client.ts().info(4)
assert 10 == info.retention_msecs