Skip to content

Commit 8b425a7

Browse files
author
rsora
committed
Refactor daemon start fixture to include daemon process cleanup
1 parent aaed29d commit 8b425a7

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

test/conftest.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# software without disclosing the source code of your own applications. To purchase
1414
# a commercial license, send an email to [email protected].
1515
import os
16+
import platform
17+
import signal
1618

1719
import pytest
1820
import simplejson as json
@@ -105,7 +107,14 @@ def daemon_runner(pytestconfig, data_dir, downloads_dir, working_dir):
105107
cli_full_line, echo=False, hide=True, warn=True, env=env, asynchronous=True
106108
)
107109

108-
return runner
110+
# we block here until the test function using this fixture has returned
111+
yield runner
112+
113+
# Kill the runner's process as we finished our test (platform dependent)
114+
os_signal = signal.SIGTERM
115+
if platform.system() != "Windows":
116+
os_signal = signal.SIGKILL
117+
os.kill(runner.process.pid, os_signal)
109118

110119

111120
@pytest.fixture(scope="function")

test/test_daemon.py

-8
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
# a commercial license, send an email to [email protected].
1515

1616
import os
17-
import platform
18-
import signal
1917
import time
2018

2119
import pytest
@@ -40,9 +38,3 @@ def test_telemetry_prometheus_endpoint(daemon_runner, data_dir):
4038
family = next(text_string_to_metric_families(metrics))
4139
sample = family.samples[0]
4240
assert inventory["installation"]["id"] == sample.labels["installationID"]
43-
44-
# Kill the runner's process as we finished our test (platform dependent)
45-
os_signal = signal.SIGTERM
46-
if platform.system() != "Windows":
47-
os_signal = signal.SIGKILL
48-
os.kill(daemon_runner.process.pid, os_signal)

0 commit comments

Comments
 (0)