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.
Action Steps
- Write tests that mimic real-world API responses, including potential errors and inconsistencies.
- Use tools like requests_mock or pytest-mock to mock API responses in tests.
- Test for edge cases, such as missing or malformed data, to ensure robustness.
- Implement error handling and logging in production code to facilitate debugging.
- 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)
[](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
0 Add reaction
0 Like 0 Unicorn 0 Exploding Head 0 Raised Hands 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)
[](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
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)
[](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
0 Add reaction
0 Like 0 Unicorn 0 Exploding Head 0 Raised Hands 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)
[](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
DeepCamp AI