Python Test

209: Testing argparse Applications

11.16.2023 - By Brian OkkenPlay

Download our free app to listen on your phone

Download on the App StoreGet it on Google Play

How do you test the argument parsing bit of an application that uses argparse? This episode covers:Design for Test: Structuring your app or script so it's easier to test.pytest & capsys for testing stdoutAdding debug and preview flags for debugging and testingAnd reverting to subprocess.run if you can't modify the code under testAlso, there's a full writeup and code samples available:Blog post: Testing argparse Applications Code Repo

The Complete pytest CourseLevel up your testing skills and save time during coding and maintenance.Check out courses.pythontest.com

More episodes from Python Test