Stabilize test_quitting_process_expected

This commit is contained in:
Florian Bruhin 2017-09-21 13:35:57 +02:00
parent 53b1ffe953
commit e0e7d4ca67
2 changed files with 8 additions and 4 deletions

View File

@ -138,9 +138,9 @@ def test_quitting_process(qtbot, quit_pyproc):
def test_quitting_process_expected(qtbot, quit_pyproc):
quit_pyproc.exit_expected = True
with qtbot.waitSignal(quit_pyproc.proc.finished):
quit_pyproc.start()
quit_pyproc.exit_expected = True
quit_pyproc.after_test()

View File

@ -125,6 +125,7 @@ class Process(QObject):
Attributes:
_invalid: A list of lines which could not be parsed.
_data: A list of parsed lines.
_started: Whether the process was ever started.
proc: The QProcess for the underlying process.
exit_expected: Whether the process is expected to quit.
@ -140,11 +141,12 @@ class Process(QObject):
def __init__(self, parent=None):
super().__init__(parent)
self.captured_log = []
self._started = False
self._invalid = []
self._data = []
self.proc = QProcess()
self.proc.setReadChannel(QProcess.StandardError)
self.exit_expected = True # Not started at all yet
self.exit_expected = None # Not started at all yet
def _log(self, line):
"""Add the given line to the captured log output."""
@ -221,8 +223,8 @@ class Process(QObject):
def start(self, args=None, *, env=None):
"""Start the process and wait until it started."""
self.exit_expected = False
self._start(args, env=env)
self._started = True
timeout = 60 if 'CI' in os.environ else 20
for _ in range(timeout):
with self._wait_signal(self.ready, timeout=1000,
@ -230,6 +232,8 @@ class Process(QObject):
pass
if not self.is_running():
if self.exit_expected:
return
# _start ensures it actually started, but it might quit shortly
# afterwards
raise ProcessExited('\n' + _render_log(self.captured_log))
@ -285,7 +289,7 @@ class Process(QObject):
raise InvalidLine('\n' + '\n'.join(self._invalid))
self.clear_data()
if not self.is_running() and not self.exit_expected:
if not self.is_running() and not self.exit_expected and self._started:
raise ProcessExited
self.exit_expected = False