From 90ed6fe31f1bdf1d0154858ae1f727bfefdbefa7 Mon Sep 17 00:00:00 2001 From: Pavel Minaev Date: Tue, 30 Oct 2018 17:33:47 -0700 Subject: [PATCH] Use backchannel instead of text output in test_subprocess to improve test reliability. --- pytests/func/test_multiproc.py | 17 +++++++++-------- pytests/helpers/session.py | 3 --- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/pytests/func/test_multiproc.py b/pytests/func/test_multiproc.py index 01fbc929..c255a176 100644 --- a/pytests/func/test_multiproc.py +++ b/pytests/func/test_multiproc.py @@ -8,9 +8,9 @@ import platform import pytest import sys -from ..helpers.pattern import ANY -from ..helpers.session import DebugSession -from ..helpers.timeline import Event, Request +from pytests.helpers.pattern import ANY +from pytests.helpers.session import DebugSession +from pytests.helpers.timeline import Event, Request @pytest.mark.timeout(60) @@ -144,7 +144,8 @@ def test_subprocess(debug_session, pyfile): @pyfile def child(): import sys - print(' '.join(sys.argv)) + import backchannel + backchannel.write_json(sys.argv) @pyfile def parent(): @@ -159,7 +160,7 @@ def test_subprocess(debug_session, pyfile): debug_session.multiprocess = True debug_session.program_args += [child] - debug_session.prepare_to_run(filename=parent) + debug_session.prepare_to_run(filename=parent, backchannel=True) debug_session.start_debugging() root_start_request, = debug_session.all_occurrences_of(Request('launch') | Request('attach')) @@ -180,15 +181,15 @@ def test_subprocess(debug_session, pyfile): } }) child_port = child_subprocess.body['port'] + debug_session.proceed() child_session = DebugSession(method='attach_socket', ptvsd_port=child_port) child_session.ignore_unobserved = debug_session.ignore_unobserved child_session.connect() child_session.handshake() child_session.start_debugging() - debug_session.proceed() - child_args_output = child_session.wait_for_next(Event('output')) - assert child_args_output.body['output'].endswith('child.py --arg1 --arg2 --arg3') + child_argv = debug_session.read_json() + assert child_argv == [child, '--arg1', '--arg2', '--arg3'] debug_session.wait_for_exit() diff --git a/pytests/helpers/session.py b/pytests/helpers/session.py index b12b342c..7f331e5b 100644 --- a/pytests/helpers/session.py +++ b/pytests/helpers/session.py @@ -373,9 +373,6 @@ class DebugSession(object): if not freeze: self.proceed() - if self.backchannel_port: - self.backchannel_established.wait() - return start def _process_event(self, event):