Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pexpect tests hang on macOS #2022

Closed
jaraco opened this issue Oct 21, 2016 · 4 comments · Fixed by #3116
Closed

pexpect tests hang on macOS #2022

jaraco opened this issue Oct 21, 2016 · 4 comments · Fixed by #3116

Comments

@jaraco
Copy link
Contributor

jaraco commented Oct 21, 2016

In #985, I discovered that many tests on macOS are bypassed because pexpect appears to operate unreliably on that platform.

@jaraco
Copy link
Contributor Author

jaraco commented Oct 21, 2016

I found that even consuming all of the input before calling .wait() doesn't stop the block forever behavior. But if instead I do something like the following, it causes child.isalive() to return False and the test to pass.

diff -r 1d9397a85c2c testing/test_pdb.py
--- a/testing/test_pdb.py   Fri Oct 21 01:36:24 2016 +0200
+++ b/testing/test_pdb.py   Fri Oct 21 12:01:25 2016 -0400
@@ -141,10 +141,20 @@
         child = testdir.spawn_pytest("--pdb %s" % p1)
         #child.expect(".*import pytest.*")
         child.expect("(Pdb)")
+        print("got here 1")
         child.sendeof()
+        print("got here 2")
         child.expect("1 error")
+        print("got here 3")
+        while True:
+            try:
+                child.read_nonblocking()
+            except Exception:
+                break
         if child.isalive():
+            print("got here 6")
             child.wait()
+        print("got here 5")

     def test_pdb_interaction_on_internal_error(self, testdir):
         testdir.makeconftest("""
$ python -m tox -e py35 -- -s -k test_pdb_interaction_on_collection_issue181 -v
GLOB sdist-make: /Users/jaraco/Dropbox/code/public/pytest/setup.py
py35 inst-nodeps: /Users/jaraco/Dropbox/code/public/pytest/.tox/dist/pytest-3.0.4.dev0.zip
py35 installed: hypothesis==3.5.3,mock==2.0.0,nose==1.3.7,pbr==1.10.0,pexpect==4.2.1,ptyprocess==0.5.1,py==1.4.31,pytest==3.0.4.dev0,requests==2.11.1,six==1.10.0,spark-parser==1.4.0,uncompyle6==2.9.2,xdis==3.1.0
py35 runtests: PYTHONHASHSEED='1622146962'
py35 runtests: commands[0] | pytest --lsof -rfsxX -s -k test_pdb_interaction_on_collection_issue181 -v
=========================================== test session starts ===========================================
platform darwin -- Python 3.5.2, pytest-3.0.4.dev, py-1.4.31, pluggy-0.4.0 -- /Users/jaraco/Dropbox/code/public/pytest/.tox/py35/bin/python3.5
cachedir: .cache
rootdir: /Users/jaraco/Dropbox/code/public/pytest, inifile: tox.ini
plugins: hypothesis-3.5.3
collected 1724 items 

testing/test_pdb.py::TestPDB::test_pdb_interaction_on_collection_issue181 got here 1
got here 2
got here 3
got here 5
PASSED

========================================== 1723 tests deselected ==========================================
================================ 1 passed, 1723 deselected in 2.42 seconds ================================
_________________________________________________ summary _________________________________________________
  py35: commands succeeded
  congratulations :)

@jaraco jaraco changed the title pexpect tests fail on macOS pexpect tests hang on macOS Oct 21, 2016
@brianmaissy
Copy link
Contributor

Reappeared in test_pdb_custom_cls_with_settrace in d75748e, I'll open a PR

@zakkg3
Copy link

zakkg3 commented Nov 7, 2019

Happened to me today.

Darwin 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64
python --version Python 3.7.4

Calling ssh-keygen was hanging on .wait() : this was working in linux
Solved by read_nonblocking() and if isalive() wait()

import os
import sys

import pexpect


passphrase = os.environ['HOST_CA_KEY_PASSPHRASE']

command = 'ssh-keygen'
child = pexpect.spawn(command, args=sys.argv[1:])
child.expect('Enter passphrase:')
child.sendline(passphrase)

# Avoid Hang on macOS
# https://github.com/pytest-dev/pytest/issues/2022
while True:
    try:
        child.read_nonblocking()
    except Exception:
        break

if child.isalive():
    child.wait()

@blueyed
Copy link
Contributor

blueyed commented Nov 7, 2019

@zakkg3
This issue is about tests in pytest itself..

IIRC it will hang on osx with unread output.

Maybe the pytester spawn method could take care of that automatically? (i.e. read anything on test/fixture teardown)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants