Replies: 2 comments
|
selectors is directly incompatible for stdio capture - doesntit have a test mode? |
|
I would test this in two layers:
def posix_stdin_timeout(prompt="", timeout=DEFAULT_TIMEOUT, timeout_log="", selector_factory=selectors.DefaultSelector, stdin=sys.stdin):
echo(prompt)
sel = selector_factory()
sel.register(stdin, selectors.EVENT_READ)
keys_and_events = sel.select(timeout)
...Then your unit test can make
For example, the high-level shape is: def test_timeout_logic_with_fake_selector():
class FakeSelector:
def register(self, fileobj, events):
pass
def select(self, timeout):
return []
with pytest.raises(InputTimeoutError):
posix_stdin_timeout(timeout=0.01, selector_factory=FakeSelector, stdin=object())The direct test against |
Uh oh!
There was an error while loading. Please reload this page.
I have a working solution for user input timeout using
selectorsin linux/uninx andmsvcrtin windows. I have written a test that works with windows version but throwsPermissionError: [Errno 1] Operation not permitted with pytest on linux.stdin_timeout
test
These functions work fine when running as python applications but running the above test with pytest throws this error:
Is there a way I can make this test succeed?
All reactions