Testing Textual applications with pytest-bdd #5932
Replies: 2 comments
-
This is an interesting experiment and I commend you for it. I can't really speak to this particular issue, but I would recommend just becoming more familiar with how to write regular Textual tests first before diving into writing BDD tests. If as you said you are not experienced with async functions at all, I think it would be better to start there and work upwards. The FastAPI docs have an article about async programming that is very well known among the Python Community, I highly recommend it if you haven't read it: |
Beta Was this translation helpful? Give feedback.
-
Thanks for the resource! After digging some more, I have found that pytest-bdd and pytest-asyncio are unable to work together natively, and haven't been for some time (pytest-dev/pytest-bdd#223 and pytest-dev/pytest-asyncio#195). I will be closing the discussion following these findings, thanks again for your help! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys,
I am writing a Cookiecutter template to provide an initial setup for CLI/TUI apps. One of the features is the possibility of using
pytest-bdd
to write tests. The application is very simple, consisting only of a title screen:Reading the guide, testing this app is pretty straightforward and Pytest runs the test successfully:
Now, I am trying to port this test to a BDD framework, but having a lot of trouble since I'm not very familiar with async development. With a mix of my knowledge and some rounds with a LLM, I managed to come up with this code, which runs the entire test:
It seems all steps manage to run, but the test fails as
app_instance.return_code
returnsNone
by the end, indicating the Textual app has not been exited:I'm pretty sure this is just a matter of a minor fix, but being inexperienced with async functions, I must confess I am lost here. Would anyone be willing to help fixing this test? If you also have recommendations of good resources so I can finally nail how to deal with async tasks in Python, that would be very much appreciated as well! 🙂
Beta Was this translation helpful? Give feedback.
All reactions