<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/beyond-callables-in-wrapture-a41yd6lmi" -->

---
title: Beyond callables in wrapture | daily.dev
description: An in-depth look at wrapture's binding model for testing scenarios beyond simple function calls: attribute reads/writes via descriptors, module attribute...
canonical: https://daily.dev/posts/beyond-callables-in-wrapture-a41yd6lmi
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Beyond callables in wrapture | daily.dev
og:description: An in-depth look at wrapture's binding model for testing scenarios beyond simple function calls: attribute reads/writes via descriptors, module attribute...
og:url: https://daily.dev/posts/beyond-callables-in-wrapture-a41yd6lmi
og:image: https://api.daily.dev/og/posts/A41YD6LMI.png
og:image:alt: Beyond callables in wrapture
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.

# Beyond callables in wrapture

**[Planet Python](https://daily.dev/sources/planetpython)** · 12 min read · 0 upvotes · 0 comments

## Summary

An in-depth look at wrapture's binding model for testing scenarios beyond simple function calls: attribute reads/writes via descriptors, module attribute patching, value bindings for environment variables and settings, mapping bindings that mutate shared dicts in place, callables held inside dicts, and generator/iterator instrumentation that can detect early abandonment or mid-stream errors. All of these share one binding lifecycle - context manager, decorator, group, suspend/resume, and leak detection via a pytest plugin.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://grahamdumpleton.me/posts/2026/09/beyond-callables-in-wrapture>

## Questions this post answers

### How can I test that a Python generator was abandoned before it finished iterating?

Wrap the generator-returning method with a wrapture binding and attach an iterator proxy via transforms_result(). The proxy's on_abandon channel fires when a started but unexhausted generator is closed, whether explicitly or by the garbage collector after the consumer drops it, letting a test detect early termination that a canned list of pages could never reveal.

_Testing generator lifecycles for early termination is easier with patterns developers find through daily.dev._

### How do I patch a shared settings dict in Python without breaking other modules that imported it by reference?

Use a mapping-mode binding, for example wrapture.binding(config, "SETTINGS", mode="mapping"), which mutates the one dict in place instead of replacing config.SETTINGS with a new object. Any module that did `from config import SETTINGS` at import time keeps seeing the test's content because it holds the same dict, and the original entries are restored in order on exit.

_Developers picking the right mocking approach for shared config often track these patterns via daily.dev._

### What is the difference between patch.dict's default merge behavior and patch.dict(..., clear=True)?

With wrapture's mapping binding, updates() merges the named keys over the existing dict content, matching patch.dict's default behavior, while overrides() replaces the entries entirely so only the given keys remain, matching patch.dict(..., clear=True). Both act through the same object reference so other holders of the dict see the change and it is restored afterward.

_Comparing mocking library behaviors like this is common ground for daily.dev readers deciding on test strategy._

## Similar posts on daily.dev

- [Introducing wrapture](https://daily.dev/posts/introducing-wrapture-ohj3cvcws) · Planet Python · 1 upvotes · 1 comments
- [Recording calls with wrapture](https://daily.dev/posts/recording-calls-with-wrapture-hkpb9gqvx) · Planet Python · 0 upvotes · 1 comments
- [Trying out wrapture](https://daily.dev/posts/trying-out-wrapture-qi1ktjmcu) · Planet Python · 0 upvotes · 0 comments
- [Unit testing with wrapture](https://daily.dev/posts/unit-testing-with-wrapture-8myueoz61) · Planet Python · 0 upvotes · 0 comments
- [Python: spy on function calls with unittest.mock’s wraps](https://daily.dev/posts/python-spy-on-function-calls-with-unittest-mock-s-wraps-4hfdxvksm) · Adam Johnson · 1 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/beyond-callables-in-wrapture-a41yd6lmi)

```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":"Beyond callables in wrapture","url":"https://daily.dev/posts/beyond-callables-in-wrapture-a41yd6lmi","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/beyond-callables-in-wrapture-a41yd6lmi"},"datePublished":"2026-09-03T21:52:01.020Z","dateModified":"2026-09-03T23:07:24.965Z","description":"An in-depth look at wrapture's binding model for testing scenarios beyond simple function calls: attribute reads/writes via descriptors, module attribute...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/00e05f4e62515378be00a9c79f75c231?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/00e05f4e62515378be00a9c79f75c231?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Planet Python","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":"Planet Python","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/eac3cc584cb043b5a242d13752bd3d0c","url":"https://daily.dev/sources/planetpython"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/beyond-callables-in-wrapture-a41yd6lmi","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,testing","timeRequired":"PT12M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Planet Python","item":"https://daily.dev/sources/planetpython"},{"@type":"ListItem","position":3,"name":"Beyond callables in wrapture"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/beyond-callables-in-wrapture-a41yd6lmi#faq","mainEntity":[{"@type":"Question","name":"How can I test that a Python generator was abandoned before it finished iterating?","acceptedAnswer":{"@type":"Answer","text":"Wrap the generator-returning method with a wrapture binding and attach an iterator proxy via transforms_result(). The proxy's on_abandon channel fires when a started but unexhausted generator is closed, whether explicitly or by the garbage collector after the consumer drops it, letting a test detect early termination that a canned list of pages could never reveal. Testing generator lifecycles for early termination is easier with patterns developers find through daily.dev."}},{"@type":"Question","name":"How do I patch a shared settings dict in Python without breaking other modules that imported it by reference?","acceptedAnswer":{"@type":"Answer","text":"Use a mapping-mode binding, for example wrapture.binding(config, \"SETTINGS\", mode=\"mapping\"), which mutates the one dict in place instead of replacing config.SETTINGS with a new object. Any module that did `from config import SETTINGS` at import time keeps seeing the test's content because it holds the same dict, and the original entries are restored in order on exit. Developers picking the right mocking approach for shared config often track these patterns via daily.dev."}},{"@type":"Question","name":"What is the difference between patch.dict's default merge behavior and patch.dict(..., clear=True)?","acceptedAnswer":{"@type":"Answer","text":"With wrapture's mapping binding, updates() merges the named keys over the existing dict content, matching patch.dict's default behavior, while overrides() replaces the entries entirely so only the given keys remain, matching patch.dict(..., clear=True). Both act through the same object reference so other holders of the dict see the change and it is restored afterward. Comparing mocking library behaviors like this is common ground for daily.dev readers deciding on test strategy."}}]}
```

