Back to articles
My Python tests passed. Production still broke.

My Python tests passed. Production still broke.

via Dev.to PythonNico Reyes

Spent 2 hours writing tests for a data validation function. All green. Deployed to production. Broke immediately. What went wrong Had a function that validated user input from a form: def validate_email ( email ): if ' @ ' in email and ' . ' in email : return True return False Wrote tests: def test_valid_email (): assert validate_email ( ' [email protected] ' ) == True def test_invalid_email (): assert validate_email ( ' notanemail ' ) == False Tests passed. Felt good. Production users started entering stuff like user@domain (no TLD), @domain.com (no username), user.name@ (incomplete). All passed validation. Database filled with garbage emails. Had to roll back. The actual problem Testing happy path is easy. Testing edge cases takes actual thought. My tests only checked "does it have @ and ." - never tested WHERE those characters are, or if the format makes sense. What I changed Ended up using email-validator library instead of rolling my own: from email_validator import validate_email

Continue reading on Dev.to Python

Opens in a new tab

Read Full Article
7 views

Related Articles