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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ We use `pytest` to run unit tests, which you can run with:
uv run pytest
```

> [!TIP]
> You can also run tests against the [bitmapist-server](https://github.com/Doist/bitmapist-server) backend instead of Redis.
> To do this, set the `BITMAPIST_REDIS_SERVER_PATH` variable to the path of the `bitmapist-server` executable.

## Releasing new versions

1. Bump version in `pyproject.toml` (or use `uv version`)
Expand Down
19 changes: 14 additions & 5 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def redis_server(redis_settings):


@pytest.fixture(scope="session", autouse=True)
def setup_redis_for_bitmapist():
setup_redis("default", "localhost", 6399)
setup_redis("default_copy", "localhost", 6399)
setup_redis("db1", "localhost", 6399, db=1)
def setup_redis_for_bitmapist(redis_settings):
setup_redis("default", "localhost", redis_settings["port"])
setup_redis("default_copy", "localhost", redis_settings["port"])
setup_redis("db1", "localhost", redis_settings["port"], db=1)


@pytest.fixture(autouse=True)
Expand All @@ -52,8 +52,9 @@ def start_redis_server(server_path, port):
"""Helper function starting Redis server"""
devzero = open(os.devnull)
devnull = open(os.devnull, "w")
command = get_redis_command(server_path, port)
proc = subprocess.Popen(
[server_path, "--port", str(port)],
command,
stdin=devzero,
stdout=devnull,
stderr=devnull,
Expand All @@ -63,6 +64,14 @@ def start_redis_server(server_path, port):
return proc


def get_redis_command(server_path, port):
"""Run with --version to determine if this is redis or bitmapist-server"""
output = subprocess.check_output([server_path, "--version"])
if b"bitmapist-server" in output:
return [server_path, "-addr", f"0.0.0.0:{port}"]
return [server_path, "--port", str(port)]


def is_socket_open(host, port):
"""Helper function which tests is the socket open"""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand Down