-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
85 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
import pytest | ||
import psutil | ||
import subprocess | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def wrapper(): | ||
""" | ||
A wrapper function to stop the EMLE server after each test. | ||
def start_server(cwd, env=None): | ||
""" | ||
Start the EMLE server using the environment variables. | ||
yield | ||
Parameters | ||
---------- | ||
# Kill the EMLE server. | ||
kill_server() | ||
cwd : str | ||
The current working directory. | ||
env : dict | ||
The environment variables. | ||
def kill_server(): | ||
""" | ||
Helper function to kill the EMLE server. | ||
Returns | ||
------- | ||
process : subprocess.Popen | ||
The EMLE server process object. | ||
""" | ||
|
||
# Kill the EMLE server. We do this manually rather than using emle-stop | ||
# because there is sometimes a delay in the termination of the server, | ||
# which causes the next test to fail. This only seems to happen when | ||
# testing during CI. | ||
for conn in psutil.net_connections(kind="inet"): | ||
if conn.laddr.port == 10000: | ||
process = psutil.Process(conn.pid) | ||
process.terminate() | ||
break | ||
process = subprocess.Popen( | ||
["emle-server"], | ||
cwd=cwd, | ||
env=env, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
) | ||
|
||
return process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters