Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ dev = [
"pytest-mock",
"pytest-click",
"pytest-xdist",
"pytest-sugar",
"slotscheck",
"psycopg-binary", # This fixes tests failing on M series CPUs.
# lint
Expand Down
6 changes: 0 additions & 6 deletions src/pytest_databases/docker/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ def redis_service(
db = 0
if worker_num is not None:
if xdist_redis_isolation_level == "database":
container_num = worker_num // 1
name += f"_{container_num + 1}"
db = worker_num
else:
name += f"_{worker_num + 1}"
Expand Down Expand Up @@ -94,8 +92,6 @@ def dragonfly_service(
db = 0
if worker_num is not None:
if xdist_redis_isolation_level == "database":
container_num = worker_num // 1
name += f"_{container_num + 1}"
db = worker_num
else:
name += f"_{worker_num + 1}"
Expand Down Expand Up @@ -136,8 +132,6 @@ def keydb_service(
db = 0
if worker_num is not None:
if xdist_redis_isolation_level == "database":
container_num = worker_num // 1
name += f"_{container_num + 1}"
db = worker_num
else:
name += f"_{worker_num + 1}"
Expand Down
31 changes: 21 additions & 10 deletions tests/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def redis_image():
return "{redis_image_name}"

def test_redis_service(redis_service: RedisService) -> None:
assert redis.Redis.from_url("redis://", host=redis_service.host, port=redis_service.port).ping()
assert redis.Redis(host=redis_service.host, port=redis_service.port).ping()
""")
result = pytester.runpytest()
result.assert_outcomes(passed=1)
Expand All @@ -64,7 +64,7 @@ def test_default_no_xdist(pytester: pytest.Pytester, redis_compatible_service: s
]

def test_redis_service({redis_compatible_service}: RedisService) -> None:
assert redis.Redis.from_url("redis://", host={redis_compatible_service}.host, port={redis_compatible_service}.port).ping()
assert redis.Redis(host={redis_compatible_service}.host, port={redis_compatible_service}.port).ping()
""")
result = pytester.runpytest()
result.assert_outcomes(passed=1)
Expand All @@ -82,20 +82,31 @@ def test_xdist_isolate_database(pytester: pytest.Pytester, redis_compatible_serv
]

def test_one({redis_compatible_service}: RedisService) -> None:
client = redis.Redis.from_url("redis://", host={redis_compatible_service}.host, port={redis_compatible_service}.port, db={redis_compatible_service}.db)
assert not client.get("one")
client.set("one", "1")
client = redis.Redis(host={redis_compatible_service}.host, port={redis_compatible_service}.port, db={redis_compatible_service}.db)
assert {redis_compatible_service}.db == get_xdist_worker_num()
assert not client.get("one")
client.set("one", "0")
assert client.get("one") == b"0"


def test_two({redis_compatible_service}: RedisService) -> None:
client = redis.Redis.from_url("redis://", host={redis_compatible_service}.host, port={redis_compatible_service}.port, db={redis_compatible_service}.db)
client = redis.Redis(host={redis_compatible_service}.host, port={redis_compatible_service}.port, db={redis_compatible_service}.db)
assert {redis_compatible_service}.db == get_xdist_worker_num()
assert not client.get("one")
client.set("one", "1")
assert {redis_compatible_service}.db == get_xdist_worker_num()
assert client.get("one") == b"1"


def test_use_same_db({redis_compatible_service}: RedisService) -> None:
client_0 = redis.Redis(host={redis_compatible_service}.host, port={redis_compatible_service}.port, db=0)
client_1 = redis.Redis(host={redis_compatible_service}.host, port={redis_compatible_service}.port, db=1)
client_0.set("foo", "0")
client_1.set("foo", "1")
assert client_0.get("foo") == b"0"
assert client_1.get("foo") == b"1"
""")
result = pytester.runpytest("-n", "2")
result.assert_outcomes(passed=2)
result.assert_outcomes(passed=3)


def test_xdist_isolate_server(pytester: pytest.Pytester, redis_compatible_service: str) -> None:
Expand All @@ -115,14 +126,14 @@ def xdist_redis_isolation_level():


def test_one({redis_compatible_service}: RedisService) -> None:
client = redis.Redis.from_url("redis://", host={redis_compatible_service}.host, port={redis_compatible_service}.port, db={redis_compatible_service}.db)
client = redis.Redis(host={redis_compatible_service}.host, port={redis_compatible_service}.port, db={redis_compatible_service}.db)
assert not client.get("one")
client.set("one", "1")
assert {redis_compatible_service}.db == 0


def test_two({redis_compatible_service}: RedisService) -> None:
client = redis.Redis.from_url("redis://", host={redis_compatible_service}.host, port={redis_compatible_service}.port, db={redis_compatible_service}.db)
client = redis.Redis(host={redis_compatible_service}.host, port={redis_compatible_service}.port, db={redis_compatible_service}.db)
assert not client.get("one")
client.set("one", "1")
assert {redis_compatible_service}.db == 0
Expand Down
27 changes: 1 addition & 26 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading