Átomo
83Tf
pytest · Python

test_ / assert

Abrir na tabela

Definição

Testes são funções que começam por test_ e usam assert. O pytest descobre e executa todas.

Exemplos

1. Teste simples
# tests/test_transform.py
from etl.transform import clean_email

def test_clean_email_lowercases_and_strips():
    assert clean_email("  Anna@Company.COM ") == "anna@company.com"
2. Executar
pytest -v
pytest tests/test_transform.py::test_clean_email_lowercases_and_strips
3. Comparar DataFrames
import pandas as pd

def test_dedup_keeps_latest():
    result = dedup(sample_df)
    pd.testing.assert_frame_equal(result, expected_df)

No mesmo grupo