Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d53e6cc

Browse files
committedFeb 6, 2024·
test: use xprocess to ensure test server startup
1 parent 58890b4 commit d53e6cc

File tree

3 files changed

+106
-6
lines changed

3 files changed

+106
-6
lines changed
 

‎py-rattler/pixi.lock

+88
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎py-rattler/pixi.toml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ mkdocstrings = "0.23.0.*"
4545
mkdocs-material = "9.4.4.*"
4646
pillow = ">=9.4.0.*"
4747
cairosvg = "2.7.1.*"
48+
pytest-xprocess = ">=0.23.0,<0.24"
4849

4950

5051

‎py-rattler/tests/unit/test_fetch_repo_data.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
# type: ignore
22
import os.path
33
import subprocess
4+
import time
45

56
import pytest
7+
from xprocess import ProcessStarter
68
from rattler import Channel, ChannelConfig, fetch_repo_data, SparseRepoData, PackageName
79
from rattler.platform import Platform
810
from rattler.repo_data.record import RepoDataRecord
911

1012

1113
@pytest.fixture(scope="session")
12-
def serve_repo_data() -> None:
14+
def serve_repo_data(xprocess) -> None:
1315
port, repo_name = 8912, "test-repo"
1416

1517
test_data_dir = os.path.join(
1618
os.path.dirname(__file__), "../../../test-data/test-server"
1719
)
1820

19-
with subprocess.Popen(
20-
[
21+
class Starter(ProcessStarter):
22+
# startup pattern
23+
pattern = f"Server started at localhost:{port}"
24+
25+
# command to start process
26+
args = [
2127
"python",
2228
os.path.join(test_data_dir, "reposerver.py"),
2329
"-d",
@@ -27,9 +33,14 @@ def serve_repo_data() -> None:
2733
"-p",
2834
str(port),
2935
]
30-
) as proc:
31-
yield port, repo_name
32-
proc.terminate()
36+
37+
# ensure process is running and return its logfile
38+
xprocess.ensure("reposerver", Starter)
39+
40+
yield port, repo_name
41+
42+
# clean up whole process tree afterwards
43+
xprocess.getinfo("reposerver").terminate()
3344

3445

3546
@pytest.mark.asyncio

0 commit comments

Comments
 (0)
Please sign in to comment.