|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 | 15 | import os
|
| 16 | +import signal |
| 17 | +import subprocess |
16 | 18 | import sys
|
17 | 19 |
|
18 | 20 | import pytest
|
@@ -1019,3 +1021,51 @@ def test_with_page(page):
|
1019 | 1021 | "test-results/test-output-path-via-pytest-runtest-makereport-hook-py-test-with-page-chromium"
|
1020 | 1022 | ).strpath,
|
1021 | 1023 | ]
|
| 1024 | + |
| 1025 | + |
| 1026 | +def test_connect_options_should_work(testdir: pytest.Testdir) -> None: |
| 1027 | + server_process = None |
| 1028 | + try: |
| 1029 | + testdir.makeconftest( |
| 1030 | + """ |
| 1031 | + import pytest |
| 1032 | +
|
| 1033 | + @pytest.fixture(scope="session") |
| 1034 | + def connect_options(): |
| 1035 | + return { |
| 1036 | + "ws_endpoint": "ws://localhost:1234", |
| 1037 | + } |
| 1038 | + """ |
| 1039 | + ) |
| 1040 | + testdir.makepyfile( |
| 1041 | + """ |
| 1042 | + import pytest |
| 1043 | +
|
| 1044 | + @pytest.mark.asyncio(loop_scope="session") |
| 1045 | + async def test_connect_options(page): |
| 1046 | + assert await page.evaluate("1 + 1") == 2 |
| 1047 | + """ |
| 1048 | + ) |
| 1049 | + result = testdir.runpytest() |
| 1050 | + assert "connect ECONNREFUSED" in "".join(result.outlines) |
| 1051 | + server_process = subprocess.Popen( |
| 1052 | + ["playwright", "run-server", "--port=1234"], |
| 1053 | + stdout=subprocess.PIPE, |
| 1054 | + stderr=subprocess.PIPE, |
| 1055 | + ) |
| 1056 | + while True: |
| 1057 | + stdout = server_process.stdout |
| 1058 | + assert stdout |
| 1059 | + if "Listening on" in str(stdout.readline()): |
| 1060 | + break |
| 1061 | + result = testdir.runpytest() |
| 1062 | + result.assert_outcomes(passed=1) |
| 1063 | + finally: |
| 1064 | + assert server_process |
| 1065 | + # TODO: Playwright CLI on Windows via Python does not forward the signal |
| 1066 | + # hence we need to send it to the whole process group. |
| 1067 | + if sys.platform == "win32": |
| 1068 | + subprocess.run(["taskkill", "/F", "/T", "/PID", str(server_process.pid)]) |
| 1069 | + else: |
| 1070 | + os.kill(server_process.pid, signal.SIGINT) |
| 1071 | + server_process.wait() |
0 commit comments