Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thepabloaguilar/980e8e6ed7df04a6ed53399dcdb4734a to your computer and use it in GitHub Desktop.
Save thepabloaguilar/980e8e6ed7df04a6ed53399dcdb4734a to your computer and use it in GitHub Desktop.
[Article] Monkey Patching is not too bad - pytest plugin example
from returns.result import Result, Success, Failure
def example_function(arg: str) -> Result[int, str]:
if arg.isnumeric():
return Success(int(arg))
return Failure('"{0}" is not a number'.format(arg))
def test_if_failure_is_created_at_example_function(returns):
with returns.has_trace(Failure, example_function):
Success('not a number').bind(example_function)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment