Skip to content

Instantly share code, notes, and snippets.

@gidgid
Created October 1, 2020 19:31
Show Gist options
  • Save gidgid/50155968ae5c5b8291707e4d1b87db85 to your computer and use it in GitHub Desktop.
Save gidgid/50155968ae5c5b8291707e4d1b87db85 to your computer and use it in GitHub Desktop.
Regular Python functions with no validation
import pytest
from typing import Optional
from pydantic import PositiveInt, ValidationError
def get_payload(url: str, retries: PositiveInt) -> Optional[dict]: # 1
if url.startswith("http"):
# send the actual request and return the payload if valid response
return {}
return None
@pytest.mark.parametrize(
"url,retries",
[([1, 2], 3), (4, 'wrong_args')]
)
def test_get_payload_can_fail_for_invalid_args(url, retries):
with pytest.raises(AttributeError): # 2
get_payload(url=url, retries=retries) # 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment