#TestAndCode

Matthias Bachmarix@chaos.social
2025-06-01

@brianokken , thanks for your excellent episode on writing stuff down. It is always great to hear other people's thoughts on this, even if its just as a reminder. Especially if it is in this concise format.

For anybody else wanting to listen to it, this is the link: testandcode.com/episodes/223-w

#TestAndCode

Rhet Turnbull :python:RhetTbull@fosstodon.org
2023-11-21

@brianokken I enjoyed "testing argparse apps" episode of #testandcode. I write a lot of python CLIs and I usually reach for Click & CLIRunner() but for some apps where I don't want a dependency, use argparse. I use monkeypatch to patch sys.argv so I can call main() just as user would and test parsing + execution together. I use sys.exit() to set exit status so need to check this in the code too. Here's an example.

Python function:
@pytest.mark.parametrize("arg", ["--version", "-v"])
def test_version(arg, capsys, monkeypatch):
"""Test --version option"'"
monkeypatch.setattr("sys.argv", ["command", arg])
with pytest. raises (SystemExit):
main()
captured = capsys. readouterr( )
assert f"{
version _" in captured.out
clacke: exhausted pixie dream boy πŸ‡ΈπŸ‡ͺπŸ‡­πŸ‡°πŸ’™πŸ’›clacke@libranet.de
2020-05-15
> Six Principles of Readable Tests - David Seddon

testandcode.com/112

I think I agreed with every single thing said here, both by Seddon and by Okken. I've come to the same conclusions myself.

But I still got something beyond reaffirmation: Hearing them spell it out will probably help me communicate these thoughts to others, and in their discussion they also revealed a trick or two that I'll put in my pocket for my next test suite.

#testing #testandcode

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst