Created
October 1, 2020 19:31
-
-
Save gidgid/50155968ae5c5b8291707e4d1b87db85 to your computer and use it in GitHub Desktop.
Regular Python functions with no validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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