Skip to content

Commit b3b1fc6

Browse files
committed
Rework server CLI tests to actually count for coverage (#57)
1 parent dce5e94 commit b3b1fc6

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/anchovy/server.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def serve(port: int, directory: str | pathlib.Path, host: str = 'localhost'):
8686
httpd.serve_forever()
8787

8888

89-
def main():
89+
def main(arguments: list[str] | None = None):
9090
parser = argparse.ArgumentParser()
9191
parser.add_argument('-p', '--port',
9292
help='port to serve from',
@@ -96,7 +96,7 @@ def main():
9696
help='directory to serve',
9797
type=pathlib.Path,
9898
default='.')
99-
args = parser.parse_args()
99+
args = parser.parse_args(arguments)
100100
serve(args.port, args.directory)
101101

102102

test/test_server.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import contextlib
22
import pathlib
33
import socket
4-
import subprocess
5-
import sys
64
import threading
75

86
import pytest
97
import requests
108

11-
from anchovy.server import ThreadedHTTPServer
9+
from anchovy.server import main, ThreadedHTTPServer
1210
from anchovy.test_harness import run_example
1311

1412

@@ -36,14 +34,12 @@ def run_server(directory: pathlib.Path, port: int):
3634
@contextlib.contextmanager
3735
def run_server_cli(directory: pathlib.Path, port: int):
3836
args = [
39-
sys.executable, '-m', 'anchovy.server',
4037
'--port', str(port),
4138
'--directory', str(directory)
4239
]
43-
with subprocess.Popen(args) as proc:
44-
yield
45-
proc.terminate()
46-
40+
thread = threading.Thread(target=main, args=(args,), daemon=True)
41+
thread.start()
42+
yield
4743

4844

4945
@pytest.fixture(scope='module', params=[False, True])

0 commit comments

Comments
 (0)