Posts

Showing posts from November, 2025

I can't test that, it uses STDOUT (Python)

You're working with some Python code, and would like to write a test, but... "I can't test that - it uses STDOUT!" Okay, well, that's really not such a big problem to handle. The solutions to this problem are actually simple enough that you can apply them to many other situations that might otherwise encourage you to skip tests just this one time (again). In our modern age, we have the advantage of ubiquitous LLMs in browsers, IDEs, and CLIs. We shouldn't be stuck on common problems anymore, nor must we remain unaware of features in our test libraries. Rather than look at print statements as a brick wall, you can get started writing useful tests right away. So, let's talk about a few options: Pytest "capsys" fixture. This is pretty trivial. You import and mention 'capsys' in your code, and you have access to the content printed to stdout and stderror.  These are what we would call "listener fakes" - they listen to, and remember,...