Skip to content

Instantly share code, notes, and snippets.

@jangia
Last active February 5, 2025 19:52
Show Gist options
  • Select an option

  • Save jangia/b79eaa2197ed674c58ffe9b943bd4db8 to your computer and use it in GitHub Desktop.

Select an option

Save jangia/b79eaa2197ed674c58ffe9b943bd4db8 to your computer and use it in GitHub Desktop.
Parametrize tests using pytest
import re
def is_valid_email(email: str) -> bool:
return bool(re.search(r"^[\w\.\-\+']+@[\w\.\-]+\.\w+$", email))
import pytest
from email_validator import is_valid_email
@pytest.mark.parametrize(
"email",
[
"bob@builder.com",
"bob.builder@builder.org",
"bob+test@builder.com",
"bob.o'builder@builder.com"
]
)
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