Last active
February 5, 2025 19:52
-
-
Save jangia/b79eaa2197ed674c58ffe9b943bd4db8 to your computer and use it in GitHub Desktop.
Parametrize tests using pytest
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 re | |
def is_valid_email(email: str) -> bool: | |
return bool(re.search(r"^[\w\.\-\+']+@[\w\.\-]+\.\w+$", email)) |
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 email_validator import is_valid_email | |
@pytest.mark.parametrize( | |
"email", | |
[ | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"bob.o'[email protected]" | |
] | |
) | |
def test_email_is_valid(email: str): | |
assert is_valid_email(email) is True | |
@pytest.mark.parametrize( | |
"email", | |
[ | |
"random string without @", | |
"domain.com", | |
"bob@builder", | |
"@builder.com", | |
] | |
) | |
def test_email_is_not_valid(email: str): | |
assert is_valid_email(email) is False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment