Skip to content

Commit 510242e

Browse files
committed
Start our own instance of fpserver for tests
1 parent 877388f commit 510242e

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

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)

0 commit comments

Comments
 (0)