My Python tests passed. Production still broke.

📰 Dev.to · Nico Reyes

Learn how to identify and fix issues in Python APIs that pass tests but fail in production, and understand the importance of testing for real-world scenarios.

intermediate Published 31 Mar 2026
Action Steps
  1. Write tests that mimic real-world API responses, including potential errors and inconsistencies.
  2. Use tools like requests_mock or pytest-mock to mock API responses in tests.
  3. Test for edge cases, such as missing or malformed data, to ensure robustness.
  4. Implement error handling and logging in production code to facilitate debugging.
  5. Verify that tests are running in an environment similar to production to catch environment-specific issues.
Who Needs to Know This

Developers and testers on a team can benefit from this lesson to improve their testing strategies and ensure more reliable deployments.

Key Insight

💡 Tests that mock perfect API responses can still miss real-world issues, so it's essential to test for potential errors and inconsistencies.

Share This
🚨 Tests passing doesn't mean production will work! 🚨 Learn how to identify and fix issues in Python APIs #python #testing #debugging

Key Takeaways

Learn how to identify and fix issues in Python APIs that pass tests but fail in production, and understand the importance of testing for real-world scenarios.

Full Article

Title: My Python tests passed. Production still broke.

URL Source: https://dev.to/nicodev__/my-python-tests-passed-production-still-broke-5hl7

Published Time: 2026-03-31T15:25:32Z

Markdown Content:
[Skip to content](https://dev.to/nicodev__/my-python-tests-passed-production-still-broke-5hl7#main-content)

[![Image 1: DEV Community](https://media2.dev.to/dynamic/image/quality=100/https://dev-to-uploads.s3.amazonaws.com/uploads/logos/resized_logo_UQww2soKuUsjaOGNB38o.png)](https://dev.to/)

[Powered by Algolia](https://www.algolia.com/developers/?utm_source=devto&utm_medium=referral)

[Log in](https://dev.to/enter?signup_subforem=1)[Create account](https://dev.to/enter?signup_subforem=1&state=new-user)

## DEV Community

![Image 2](https://assets.dev.to/assets/heart-plus-active-9ea3b22f2bc311281db911d416166c5f430636e76b15cd5df6b3b841d830eefa.svg)0 Add reaction

![Image 3](https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg)0 Like ![Image 4](https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg)0 Unicorn ![Image 5](https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg)0 Exploding Head ![Image 6](https://assets.dev.to/assets/raised-hands-74b2099fd66a39f2d7eed9305ee0f4553df0eb7b4f11b01b6b1b499973048fe5.svg)0 Raised Hands ![Image 7](https://assets.dev.to/assets/fire-f60e7a582391810302117f987b22a8ef04a2fe0df7e3258a5f49332df1cec71e.svg)0 Fire

0 Jump to Comments 0 Save Boost

Copy link

Copied to Clipboard

[Share to X](https://twitter.com/intent/tweet?text=%22My%20Python%20tests%20passed.%20Production%20still%20broke.%22%20by%20Nico%20Reyes%20%23DEVCommunity%20https%3A%2F%2Fdev.to%2Fnicodev__%2Fmy-python-tests-passed-production-still-broke-5hl7)[Share to LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fdev.to%2Fnicodev__%2Fmy-python-tests-passed-production-still-broke-5hl7&title=My%20Python%20tests%20passed.%20Production%20still%20broke.&summary=Tests%20passed%20but%20production%20broke.%20Here%27s%20what%20my%20perfect%20mocks%20missed.&source=DEV%20Community)[Share to Facebook](https://www.facebook.com/sharer.php?u=https%3A%2F%2Fdev.to%2Fnicodev__%2Fmy-python-tests-passed-production-still-broke-5hl7)[Share to Mastodon](https://s2f.kytta.dev/?text=https%3A%2F%2Fdev.to%2Fnicodev__%2Fmy-python-tests-passed-production-still-broke-5hl7)

[Share Post via...](https://dev.to/nicodev__/my-python-tests-passed-production-still-broke-5hl7#)[Report Abuse](https://dev.to/report-abuse)

[![Image 8: Nico Reyes](https://media2.dev.to/dynamic/image/width=50,height=50,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3852065%2F91c7ad4d-a0fa-4c08-b966-06f8f0e7a577.png)](https://dev.to/nicodev__)

[Nico Reyes](https://dev.to/nicodev__)
Posted on Mar 31

# My Python tests passed. Production still broke.

[#python](https://dev.to/t/python)[#debugging](https://dev.to/t/debugging)[#testing](https://dev.to/t/testing)[#webdev](https://dev.to/t/webdev)

Deployed my Python API to production last Friday. All tests green. Felt good about it.

Monday morning support messages me. API returning 500 errors for about 30% of requests. Tests still passing locally.

Great.

## [](https://dev.to/nicodev__/my-python-tests-passed-production-still-broke-5hl7#what-broke) What broke

My code parsed JSON from an external API:

```
import requests

def get_user_data(user_id):
response = requests.get(f"https://api.example.com/users/{user_id}")
data = response.json()
return {
'name': data['profile']['name'],
'email': data['contact']['email'],
'age': data['profile']['age']
}
```

Tests mocked the API response with perfect JSON. Every field present. Proper nesting. Exactly what I expected and nothing like what actually came back half the time.

Production API s
Read full article → ← Back to Reads