Skip to content

Commit 12c0829

Browse files
authored
Start only two HTTP servers during the test run (#185)
Previously we start N servers for N tests. This was not showing up as issues yet but N is only 91 at this point... Refactor so we start one server for static tests and one for simulated repositories. Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent b8f2205 commit 12c0829

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

tuf_conformance/conftest.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from collections.abc import Iterator
2+
from functools import cache
33

44
import pytest
55

@@ -32,25 +32,32 @@ def pytest_addoption(parser: pytest.Parser) -> None:
3232
)
3333

3434

35+
def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None:
36+
_simulator_server("").server_close()
37+
_static_server().server_close()
38+
39+
40+
@cache
41+
def _simulator_server(dump_dir: str) -> SimulatorServer:
42+
return SimulatorServer(dump_dir)
43+
44+
45+
@cache
46+
def _static_server() -> StaticServer:
47+
return StaticServer()
48+
49+
3550
@pytest.fixture
36-
def server(pytestconfig: pytest.Config) -> Iterator[SimulatorServer]:
37-
"""
38-
Parametrize each test with the server under test.
39-
"""
51+
def server(pytestconfig: pytest.Config) -> SimulatorServer:
52+
"""HTTP Server for all simulated repositories"""
4053
dump_dir = pytestconfig.getoption("--repository-dump-dir")
41-
server = SimulatorServer(dump_dir)
42-
yield server
43-
server.server_close()
54+
return _simulator_server(dump_dir)
4455

4556

4657
@pytest.fixture
47-
def static_server(pytestconfig: pytest.Config) -> Iterator[StaticServer]:
48-
"""
49-
Server that serves static repositories
50-
"""
51-
server = StaticServer()
52-
yield server
53-
server.server_close()
58+
def static_server(pytestconfig: pytest.Config) -> StaticServer:
59+
"""HTTP Server for all static repositories"""
60+
return _static_server()
5461

5562

5663
@pytest.fixture

0 commit comments

Comments
 (0)