<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/mocking-in-integration-tests-what-should-stay-real--k9wvi6bwl" -->

---
title: Mocking in Integration Tests: What Should Stay Real?
description: Whether to mock a dependency in an integration test depends on what the test is meant to check, not a fixed rule. A book-price API calls an external rates...
canonical: https://daily.dev/posts/mocking-in-integration-tests-what-should-stay-real--k9wvi6bwl
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Mocking in Integration Tests: What Should Stay Real? | daily.dev
og:description: Whether to mock a dependency in an integration test depends on what the test is meant to check, not a fixed rule. A book-price API calls an external rates...
og:url: https://daily.dev/posts/mocking-in-integration-tests-what-should-stay-real--k9wvi6bwl
og:image: https://api.daily.dev/og/posts/k9wVi6BwL.png
og:image:alt: Mocking in Integration Tests: What Should Stay Real?
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Mocking in Integration Tests: What Should Stay Real?

**[Gil Zilberfeld - Everyday Unit Testing](https://daily.dev/sources/testingil)** · 4 min read · 0 upvotes · 0 comments

## Summary

Whether to mock a dependency in an integration test depends on what the test is meant to check, not a fixed rule. A book-price API calls an external rates service; one version tests both together, another mocks get_rate with monkeypatch to isolate the conversion logic. Third-party dependencies you don't own, that are slow or expensive, are usually good mocking candidates, but sometimes testing the real integration is the whole point. AI can generate tests with or without mocks, but unless you tell it what you want, it will choose for you.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://testingil.com/2026/11/mocking-in-integration-tests.html>

## Questions this post answers

### should I mock a third-party API call in an integration test or let it run for real

It depends on what the test is meant to check. Dependencies you don't own, that are slow, expensive, or inconsistent (like a third-party rates API) are good mocking candidates when you want to isolate your own logic. But if the integration itself is the point, testing it for real is the right call. Design the test around the specific behavior you want to verify first, then decide.

_Clarifying when to mock versus test for real helps teams writing integration tests on daily.dev stay consistent._

### how do I mock a function with monkeypatch in a Python Flask test

Use pytest's monkeypatch.setattr to replace the function on its module before calling the endpoint, for example monkeypatch.setattr(bookstore, 'get_rate', lambda currency: 0.5). Then a client.get() request to the Flask route exercises the real endpoint logic while the dependency returns a fixed value, letting you assert on a deterministic computed result like a converted price.

_Developers isolating Flask dependencies in tests can find worked monkeypatch examples like this on daily.dev._

### can AI generate integration tests with the right mocking choices on its own

Not reliably. AI can generate tests either with or without mocks, but it has no way of knowing which behavior you actually want to verify unless you tell it explicitly. The responsibility for deciding what should be mocked and what should stay real still falls on the person directing the AI, not the AI itself.

_Anyone directing AI to write tests can track guidance like this on daily.dev before trusting the output._

## Similar posts on daily.dev

- [How to test agent skills without hitting real APIs](https://daily.dev/posts/how-to-test-agent-skills-without-hitting-real-apis-oz8x5b0z1) · DevBlogs · 0 upvotes · 0 comments
- [AI-Generated Tests: The Hidden Cost](https://daily.dev/posts/ai-generated-tests-the-hidden-cost-rpkboiibf) · ProAndroidDev · 1 upvotes · 0 comments
- [How Cloud-Native Complexity is Outpacing Test Automation Strategy](https://daily.dev/posts/how-cloud-native-complexity-is-outpacing-test-automation-strategy-aizwf7ic6) · Cloud Native Now · 0 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python), [#testing](https://daily.dev/tags/testing)

[View this post on daily.dev](https://daily.dev/posts/mocking-in-integration-tests-what-should-stay-real--k9wvi6bwl)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Mocking in Integration Tests: What Should Stay Real?","url":"https://daily.dev/posts/mocking-in-integration-tests-what-should-stay-real--k9wvi6bwl","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/mocking-in-integration-tests-what-should-stay-real--k9wvi6bwl"},"datePublished":"2026-11-02T08:06:43.428Z","dateModified":"2026-11-02T08:07:28.594Z","description":"Whether to mock a dependency in an integration test depends on what the test is meant to check, not a fixed rule. A book-price API calls an external rates...","image":"https://i0.wp.com/testingil.com/wp-content/uploads/2026/05/cropped-Testingil-logo-2026.png?fit=760%2C558\u0026ssl=1","thumbnailUrl":"https://i0.wp.com/testingil.com/wp-content/uploads/2026/05/cropped-Testingil-logo-2026.png?fit=760%2C558\u0026ssl=1","isAccessibleForFree":true,"articleSection":"Gil Zilberfeld - Everyday Unit Testing","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Gil Zilberfeld - Everyday Unit Testing","logo":"https://media.daily.dev/image/upload/s--mBrZysP---/f_auto,q_auto/v1788684993/logos/testingil?_a=BAMAMicg0","url":"https://daily.dev/sources/testingil"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/mocking-in-integration-tests-what-should-stay-real--k9wvi6bwl","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,testing","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Gil Zilberfeld - Everyday Unit Testing","item":"https://daily.dev/sources/testingil"},{"@type":"ListItem","position":3,"name":"Mocking in Integration Tests: What Should Stay Real?"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/mocking-in-integration-tests-what-should-stay-real--k9wvi6bwl#faq","mainEntity":[{"@type":"Question","name":"should I mock a third-party API call in an integration test or let it run for real","acceptedAnswer":{"@type":"Answer","text":"It depends on what the test is meant to check. Dependencies you don't own, that are slow, expensive, or inconsistent (like a third-party rates API) are good mocking candidates when you want to isolate your own logic. But if the integration itself is the point, testing it for real is the right call. Design the test around the specific behavior you want to verify first, then decide. Clarifying when to mock versus test for real helps teams writing integration tests on daily.dev stay consistent."}},{"@type":"Question","name":"how do I mock a function with monkeypatch in a Python Flask test","acceptedAnswer":{"@type":"Answer","text":"Use pytest's monkeypatch.setattr to replace the function on its module before calling the endpoint, for example monkeypatch.setattr(bookstore, 'get_rate', lambda currency: 0.5). Then a client.get() request to the Flask route exercises the real endpoint logic while the dependency returns a fixed value, letting you assert on a deterministic computed result like a converted price. Developers isolating Flask dependencies in tests can find worked monkeypatch examples like this on daily.dev."}},{"@type":"Question","name":"can AI generate integration tests with the right mocking choices on its own","acceptedAnswer":{"@type":"Answer","text":"Not reliably. AI can generate tests either with or without mocks, but it has no way of knowing which behavior you actually want to verify unless you tell it explicitly. The responsibility for deciding what should be mocked and what should stay real still falls on the person directing the AI, not the AI itself. Anyone directing AI to write tests can track guidance like this on daily.dev before trusting the output."}}]}
```

