ZERODROP
← INTEGRATIONSDOCS
pytestPythonGitHub Actions

Testing Email Flows in Python with pytest

Test OTP and magic link email flows in pytest without Docker, MailHog, or regex. ZeroDrop's Python SDK catches emails at the edge — email.otp and email.magic_link auto-extracted.

Install

pip install zerodrop

No dependencies. Python 3.8+. No API key required.

Basic pytest example

from zerodrop import ZeroDrop

mail = ZeroDrop()

def test_signup_email_verification(page):
    inbox = mail.generate_inbox()

    page.goto("/signup")
    page.fill('[name="email"]', inbox)
    page.fill('[name="password"]', "TestPassword123!")
    page.click('[type="submit"]')

    email = mail.wait_for_latest(inbox, timeout=15000)

    # OTP auto-extracted — no regex needed
    assert email.otp is not None
    page.fill('[name="otp"]', email.otp)
    page.click('[type="submit"]')

    assert page.url.endswith("/dashboard")

pytest fixtures (conftest.py)

# conftest.py
import pytest
from zerodrop import ZeroDrop

@pytest.fixture(scope="session")
def mail():
    return ZeroDrop()

@pytest.fixture
def inbox(mail):
    """Fresh inbox per test — no shared state."""
    return mail.generate_inbox()


# test_auth.py
def test_magic_link_login(page, mail, inbox):
    page.goto("/login")
    page.fill('[name="email"]', inbox)
    page.click('button:text("Send magic link")')

    email = mail.wait_for_latest(inbox, timeout=15000)

    assert email.magic_link is not None
    page.goto(email.magic_link)
    assert page.url.endswith("/dashboard")

Email filtering

from zerodrop import ZeroDrop, ZeroDropFilter

mail = ZeroDrop()

def test_otp_with_filter(page, inbox):
    page.goto("/signup")
    page.fill('[name="email"]', inbox)
    page.click('[type="submit"]')

    # Filter by sender and OTP presence
    email = mail.wait_for_latest(
        inbox,
        timeout=15000,
        filter_=ZeroDropFilter(
            from_="[email protected]",
            has_otp=True,
        )
    )

    assert email.otp is not None
    page.fill('[name="otp"]', email.otp)
    page.click('[type="submit"]')

GitHub Actions CI

name: E2E Tests

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - run: pip install -r requirements.txt
      - run: playwright install --with-deps chromium
      - run: pytest tests/e2e/ -v

No Docker. No SMTP service. ZeroDrop works out of the box.

What you're actually testing

Real email delivery from your app's email provider
OTP codes are valid and accepted by your backend
Magic links contain correct tokens and redirect properly
Password reset flow works end to end
Parallel test isolation — each test gets its own inbox

Ready to test your email flows in Python?

pip install zerodrop · No signup · No Docker · Works in CI in 5 minutes.

OPEN INBOX →

RELATED GUIDES

zerodrop on PyPIPython SDK on GitHubPython SDK docsFull article on dev.to