diff --git a/tests/integration/test_testprocess.py b/tests/integration/test_testprocess.py index 9508951f2..523af3b66 100644 --- a/tests/integration/test_testprocess.py +++ b/tests/integration/test_testprocess.py @@ -90,6 +90,18 @@ class QuitPythonProcess(PythonProcess): return (sys.executable, ['-c', ';'.join(code)]) +class NoReadyPythonProcess(PythonProcess): + + """A testprocess which never emits 'ready' and quits.""" + + def _executable_args(self): + code = [ + 'import sys', + 'sys.exit(0)', + ] + return (sys.executable, ['-c', ';'.join(code)]) + + @pytest.yield_fixture def pyproc(): proc = PythonProcess() @@ -104,6 +116,20 @@ def quit_pyproc(): proc.terminate() +@pytest.yield_fixture +def noready_pyproc(): + proc = NoReadyPythonProcess() + yield proc + proc.terminate() + + +def test_no_ready_python_process(noready_pyproc): + """When a process quits immediately, waiting for start should interrupt.""" + with pytest.raises(testprocess.ProcessExited): + with stopwatch(max_ms=5000): + noready_pyproc.start() + + def test_quitting_process(qtbot, quit_pyproc): with qtbot.waitSignal(quit_pyproc.proc.finished): quit_pyproc.start() diff --git a/tests/integration/testprocess.py b/tests/integration/testprocess.py index 7189d0e6d..d242a0f95 100644 --- a/tests/integration/testprocess.py +++ b/tests/integration/testprocess.py @@ -215,8 +215,21 @@ class Process(QObject): def start(self, args=None, *, env=None): """Start the process and wait until it started.""" - with self._wait_signal(self.ready, timeout=60000): - self._start(args, env=env) + self._start(args, env=env) + for _ in range(30): + with self._wait_signal(self.ready, timeout=1000, + raising=False) as blocker: + pass + + if not self.is_running(): + # _start ensures it actually started, but it might quit shortly + # afterwards + raise ProcessExited() + + if blocker.signal_triggered: + return + + raise WaitForTimeout("Timed out while waiting for process start.") def _start(self, args, env): """Actually start the process."""