From fa4388835c18bb21dad2a53a5ec9192507b03ff0 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 1 Aug 2022 15:08:15 -0400 Subject: [PATCH] Add an expect wrapper, use in hanging CI test --- tests/test_debugger.py | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tests/test_debugger.py b/tests/test_debugger.py index e42099d..2780e3e 100644 --- a/tests/test_debugger.py +++ b/tests/test_debugger.py @@ -96,6 +96,34 @@ def spawn( return _spawn +PROMPT = r"\(Pdb\+\+\)" + + +def expect( + child, + + # prompt by default + patt: str = PROMPT, + + **kwargs, + +) -> None: + ''' + Expect wrapper that prints last seen console + data before failing. + + ''' + try: + child.expect( + patt, + **kwargs, + ) + except TIMEOUT: + before = str(child.before.decode()) + print(before) + raise + + def assert_before( child, patts: list[str], @@ -174,7 +202,7 @@ def test_root_actor_error(spawn, user_in_out): child = spawn('root_actor_error') # scan for the pdbpp prompt - child.expect(r"\(Pdb\+\+\)") + expect(child, PROMPT) before = str(child.before.decode()) @@ -186,7 +214,7 @@ def test_root_actor_error(spawn, user_in_out): child.sendline(user_input) # process should exit - child.expect(pexpect.EOF) + expect(child, EOF) assert expect_err_str in str(child.before) @@ -742,7 +770,7 @@ def test_multi_nested_subactors_error_through_nurseries( assert "NameError" in before -@pytest.mark.timeout(20) +@pytest.mark.timeout(15) def test_root_nursery_cancels_before_child_releases_tty_lock( spawn, start_method, @@ -807,7 +835,7 @@ def test_root_nursery_cancels_before_child_releases_tty_lock( else: print('giving up on child releasing, sending `quit` cmd') child.sendline('q') - child.expect(pexpect.EOF) + expect(child, EOF) if not timed_out_early: before = str(child.before.decode())