Skip to content

Commit

Permalink
late eval of the skip condition (#2248)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
kristjanvalur authored Jun 27, 2022
1 parent 63cf7ec commit 8b18d5b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_asyncio/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_asyncio/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b18d5b

Please sign in to comment.