Skip to content

Commit 17ce309

Browse files
authored
Support testing with bitmapist-server (#82)
* fix: Honour custom post in tests * feat: Support running tests with bitmapist-server
1 parent 046dd95 commit 17ce309

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@ We use `pytest` to run unit tests, which you can run with:
358358
uv run pytest
359359
```
360360

361+
> [!TIP]
362+
> You can also run tests against the [bitmapist-server](https://github.com/Doist/bitmapist-server) backend instead of Redis.
363+
> To do this, set the `BITMAPIST_REDIS_SERVER_PATH` variable to the path of the `bitmapist-server` executable.
364+
361365
## Releasing new versions
362366

363367
1. Bump version in `pyproject.toml` (or use `uv version`)

test/conftest.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def redis_server(redis_settings):
3737

3838

3939
@pytest.fixture(scope="session", autouse=True)
40-
def setup_redis_for_bitmapist():
41-
setup_redis("default", "localhost", 6399)
42-
setup_redis("default_copy", "localhost", 6399)
43-
setup_redis("db1", "localhost", 6399, db=1)
40+
def setup_redis_for_bitmapist(redis_settings):
41+
setup_redis("default", "localhost", redis_settings["port"])
42+
setup_redis("default_copy", "localhost", redis_settings["port"])
43+
setup_redis("db1", "localhost", redis_settings["port"], db=1)
4444

4545

4646
@pytest.fixture(autouse=True)
@@ -52,8 +52,9 @@ def start_redis_server(server_path, port):
5252
"""Helper function starting Redis server"""
5353
devzero = open(os.devnull)
5454
devnull = open(os.devnull, "w")
55+
command = get_redis_command(server_path, port)
5556
proc = subprocess.Popen(
56-
[server_path, "--port", str(port)],
57+
command,
5758
stdin=devzero,
5859
stdout=devnull,
5960
stderr=devnull,
@@ -63,6 +64,14 @@ def start_redis_server(server_path, port):
6364
return proc
6465

6566

67+
def get_redis_command(server_path, port):
68+
"""Run with --version to determine if this is redis or bitmapist-server"""
69+
output = subprocess.check_output([server_path, "--version"])
70+
if b"bitmapist-server" in output:
71+
return [server_path, "-addr", f"0.0.0.0:{port}"]
72+
return [server_path, "--port", str(port)]
73+
74+
6675
def is_socket_open(host, port):
6776
"""Helper function which tests is the socket open"""
6877
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

0 commit comments

Comments
 (0)