Skip to content

Commit a8c7b90

Browse files
committed
Use enter to open webui: Support mac/unix style newlines & fix test case.
1 parent 5984304 commit a8c7b90

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Diff for: locust/main.py

+1
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ def start_automatic_run():
595595
if runner.state != "spawning"
596596
else logging.warning("Spawning users, can't stop right now"),
597597
"\r": lambda: webbrowser.open_new_tab(url),
598+
"\n": lambda: webbrowser.open_new_tab(url),
598599
},
599600
)
600601
)

Diff for: locust/test/test_main.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -942,14 +942,14 @@ def test_autospawn_browser(self):
942942
"""
943943
944944
from pytest import MonkeyPatch
945-
import os
945+
import sys
946946
import webbrowser
947947
948948
monkeypatch = MonkeyPatch()
949949
950-
def open_new_tab():
951-
print("browser opened")
952-
os.exit(42)
950+
def open_new_tab(url):
951+
print("browser opened with url", url)
952+
sys.exit(0)
953953
954954
monkeypatch.setattr(webbrowser, "open_new_tab", open_new_tab)
955955
print("patched")
@@ -975,16 +975,15 @@ def t(self):
975975
stdout=PIPE,
976976
text=True,
977977
)
978-
gevent.sleep(2)
979-
stdin.write("\r")
978+
gevent.sleep(1)
979+
stdin.write(b"\n")
980980
try:
981-
output, _ = proc.communicate(timeout=3)
981+
output, _ = proc.communicate(timeout=1)
982982
except Exception:
983983
proc.kill()
984-
output, _ = proc.communicate(timeout=1)
984+
output, _ = proc.communicate()
985985

986-
self.assertIn("browser opened", output.decode("UTF-8"))
987-
self.assertEqual(42, proc.returncode)
986+
self.assertIn("browser opened", output)
988987

989988
def test_spawning_with_fixed(self):
990989
LOCUSTFILE_CONTENT = textwrap.dedent(

0 commit comments

Comments
 (0)