Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: tests/utils.py

Issue 29912588: Issue 7019 - [CMS] Refactor `test_server.py` (Closed)
Patch Set: Addressed comments from Patch Set #3 Created Oct. 23, 2018, 4:42 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/utils.py
diff --git a/tests/utils.py b/tests/utils.py
index ed21e24c650e59651cd2a6edcf9d1cd915c9a38e..fda4cfe4f55d6be0ff314b41ec58445c5faf7c4f 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -37,20 +37,35 @@ def get_dir_contents(path):
@contextlib.contextmanager
-def run_test_server(site_path):
+def run_test_server(site_path, new_env=None):
"""Run test server, yield its URL. Terminate server on next iteration.
This function is intended be used in a pytest fixture.
+
+ Parameters
+ ----------
+ site_path: str
+ The path to the website's source code.
+ new_env: dict
+ The environment under which the server will be run. If `None`, this
+ will be inherited from the main process.
+
+ Returns
+ -------
+ str
+ The url where the server runs.
+
"""
args = ['python', 'runserver.py', site_path]
# Werkzeug is a dependency of flask which we are using for the mock api
# however there is an issue with Werkzeug that prevents it from properly
# handling the SIGTERM sent by p.kill() or terminate()
# Issue: https://github.com/pallets/werkzeug/issues/58
- p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid)
+ p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid,
+ env=new_env)
time.sleep(0.5)
yield 'http://localhost:5000/'
- os.killpg(os.getpgid(p.pid), signal.SIGTERM)
+ os.killpg(os.getpgid(p.pid), signal.SIGINT)
def create_in_memory_zip(file_names, file_data):
« tests/test_dynamic_server.py ('K') | « tests/test_page_outputs.py ('k') | tox.ini » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld