Open gamesbook opened 2 years ago
This is a topic I am actually also interested in. Until now, I don't know how to do this because of the interactive part of the menu and the stream of text with control characters which is written.
Is there no way for a test to simulate passing a menu choice to the menu "function" and checking that the right menu item is called? SO suggests using a monkeypatch for this - https://stackoverflow.com/questions/35851323/how-to-test-a-function-with-input-call
Ok, this is already a good point. But I think we also need a kind of terminal emulator to check if the generated output escape sequences cause the right menu display. We need something like Selenium, but for a terminal application. After a quick search, I could not find anything like this (yet).
https://twitter.com/willmcgugan is working on rich
and textual
which are libraries heavily focused on console/terminal applications. He might have some ideas/approaches for testing.
I'm also working on a TUI application, and I was wondering about a similar thing. I wanted to provide arbitrary input to generate fizz cases for my application. The closest I got was using subprocess and trying o send strings to it through stdin. I also just found these 2 resources that could potentially be a starting point https://www.youtube.com/watch?v=1aVe7bny5_Y https://stackoverflow.com/questions/70947472/how-can-i-send-keystrokes-and-mouse-movement-to-a-specific-pid
Are there any guidelines for how to use pytest to interact with a "live" menu and validate it handles and processes all items?