Skip to content

Commit ae27a8f

Browse files
authored
Merge pull request #38 from acoustid/python-tests-in-ci
Run integration tests in GitHub Actions
2 parents 0fa9c95 + 510242e commit ae27a8f

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

.github/workflows/build.yml

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ jobs:
2222
- run: zig build test --summary all
2323
- run: zig build
2424

25+
- uses: actions/setup-python@v5
26+
with:
27+
python-version: '3.13'
28+
cache: 'pip'
29+
30+
- run: pip install -r tests/requirements.txt
31+
- run: pytest -v tests/
32+
2533
- name: Log in to the Container registry
2634
if: github.event_name != 'pull_request'
2735
uses: docker/login-action@v3

tests/conftest.py

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,42 @@
11
import requests
22
import pytest
3+
import subprocess
4+
import socket
35
from urllib.parse import urljoin
46

57

8+
@pytest.fixture(scope='session')
9+
def server_port():
10+
sock = socket.socket()
11+
sock.bind(('', 0))
12+
return sock.getsockname()[1]
13+
14+
15+
@pytest.fixture(scope='session')
16+
def server(server_port, tmp_path_factory):
17+
tmp_dir = tmp_path_factory.mktemp("server")
18+
data_dir = tmp_dir / 'data'
19+
stderr = tmp_dir / 'server.stderr.log'
20+
command = [
21+
'zig-out/bin/fpindex',
22+
'--dir', str(data_dir),
23+
'--port', str(server_port),
24+
'--log-level', 'debug',
25+
]
26+
process = subprocess.Popen(
27+
command,
28+
stdin=subprocess.DEVNULL,
29+
stdout=subprocess.DEVNULL,
30+
stderr=stderr.open('w'),
31+
)
32+
yield
33+
process.terminate()
34+
retcode = process.wait()
35+
if retcode != 0:
36+
for line in stderr.read_text().splitlines():
37+
print(line)
38+
39+
640
@pytest.fixture
741
def index_name():
842
return 'testidx'
@@ -36,8 +70,8 @@ def session():
3670

3771

3872
@pytest.fixture
39-
def client(session):
40-
return Client(session, 'http://localhost:8080')
73+
def client(session, server_port, server):
74+
return Client(session, f'http://localhost:{server_port}')
4175

4276

4377
@pytest.fixture(autouse=True)

tests/requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pytest
2+
requests

0 commit comments

Comments
 (0)