andfoy / pywinpty

Pseudoterminals for Windows in Python
MIT License
118 stars 27 forks source link

test_ptyprocess.py terminating early due to child process exit #197

Open niyas-sait opened 3 years ago

niyas-sait commented 3 years ago

I've been trying to port pywinpty for windows on arm64 platform and while trying to run the unit tests (using python runtests.py or pytest) the tests terminate early during executing tests from test_ptyprocess.py.

I think this happens when we try to terminate a forked child by os.kill or an exit statement to the application.

I've tried this on the x64 windows as well and I see the same behavior. I've tried powershell and cmd and observed the same behaviour for both.

I don't know if this is an issue with the test framework or I am doing it wrong.

OS: Windows 10
Platform: ARM64
Python Version: 3.10
PyWinPty: (0d681680)
Terminal: Powershell and Cmd
niyas-sait commented 3 years ago

@andfoy Thoughts ?

niyas-sait commented 3 years ago

Looks like the test has been progressing it is just that I don't get to see the output on the terminal anymore. If I pipe the output to a file then I can see that tests are all passing as expected.

============================= test session starts =============================
platform win32 -- Python 3.10.0rc1, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- C:\Users\niysai01\Workspace\venv_310\Scripts\python.exe
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('C:\\Users\\niysai01\\Workspace\\pywinpty\\.hypothesis\\examples')
rootdir: C:\Users\niysai01\Workspace\pywinpty
plugins: anyio-3.3.4, flaky-3.7.0, hypothesis-6.24.0, nbval-0.9.6, asyncio-0.16.0, cov-3.0.0, forked-1.3.0, lazy-fixture-0.6.3, subtests-0.5.0, timeout-2.0.1, xdist-2.4.0
collecting ... collected 23 items

winpty/tests/test_pty.py::test_read[conpty_provider] PASSED              [  4%]
winpty/tests/test_pty.py::test_write[conpty_provider] PASSED             [  8%]
winpty/tests/test_pty.py::test_isalive[conpty_provider] PASSED           [ 13%]
winpty/tests/test_pty.py::test_agent_spawn_fail[conpty_provider] PASSED  [ 17%]
winpty/tests/test_pty.py::test_pty_create_size_fail[ConPTY-0] PASSED     [ 21%]
winpty/tests/test_pty.py::test_pty_create_size_fail[WinPTY-1] PASSED     [ 26%]
winpty/tests/test_pty.py::test_agent_resize_fail[conpty_provider] PASSED [ 30%]
winpty/tests/test_pty.py::test_agent_resize[conpty_provider] PASSED      [ 34%]
winpty/tests/test_ptyprocess.py::test_read[ConPTY] PASSED                [ 39%]
winpty/tests/test_ptyprocess.py::test_write[ConPTY] PASSED               [ 43%]
winpty/tests/test_ptyprocess.py::test_isalive[ConPTY] PASSED             [ 47%]
winpty/tests/test_ptyprocess.py::test_readline[ConPTY] PASSED            [ 52%]
winpty/tests/test_ptyprocess.py::test_close[ConPTY] PASSED               [ 56%]
winpty/tests/test_ptyprocess.py::test_flush[ConPTY] PASSED               [ 60%]
winpty/tests/test_ptyprocess.py::test_intr[ConPTY] PASSED                [ 65%]
winpty/tests/test_ptyprocess.py::test_send_control[ConPTY] PASSED        [ 69%]
winpty/tests/test_ptyprocess.py::test_send_eof[ConPTY] PASSED            [ 73%]
winpty/tests/test_ptyprocess.py::test_isatty[ConPTY] PASSED              [ 78%]
winpty/tests/test_ptyprocess.py::test_wait[ConPTY] PASSED                [ 82%]
winpty/tests/test_ptyprocess.py::test_exit_status[ConPTY] PASSED         [ 86%]
winpty/tests/test_ptyprocess.py::test_kill[ConPTY] PASSED                [ 91%]
winpty/tests/test_ptyprocess.py::test_getwinsize[ConPTY] PASSED          [ 95%]
winpty/tests/test_ptyprocess.py::test_setwinsize[ConPTY] PASSED          [100%]
===Flaky Test Report===

test_isalive[ConPTY] passed 1 out of the required 1 times. Success!

===End Flaky Test Report===

============================= 23 passed in 8.86s ==============================
andfoy commented 3 years ago

This is weird, since standard streams are being recreated in case the parent has redirected them:

https://github.com/spyder-ide/pywinpty/blob/bceb88334eea2355cab2216b8cead091dbb7246e/src/csrc/conpty_common.cpp#L94

Did the error occur on a cmd prompt?

niyas-sait commented 3 years ago

Did the error occur on a cmd prompt?

yes, I've tried both cmd prompt and powershell. Same behaviour observed

andfoy commented 2 years ago

@nsait-linaro, do you know if this issue still occurs with the latest release?