Replies: 2 comments 1 reply
-
Argparse is hostile to negative unittesting, as such those hacks are pretty much what I'd expect to crop up |
Beta Was this translation helpful? Give feedback.
0 replies
-
With Python 3.9+, set For older Python versions, override the @RonnyPfannschmidt I really fail to see how this is "hostile to negative unittesting". Quite the opposite. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When using pytest to test my CLIs, I often want to capture exceptions thrown by
argparse
during argument parsing. Because argparse throws aSystemExit
, this is what pytest catches. If I want to test the type and/or message of the originalArgumentError
, I either have to use something likecapsys
or I have to do some under-the-hood context unpacking.Option 1
Option 2 (stolen shamelessly from https://stackoverflow.com/a/67107620/459780)
Both of these feel like dirty hacks. Is there a better, cleaner way to write such tests?
Beta Was this translation helpful? Give feedback.
All reactions