Skip to content

Instantly share code, notes, and snippets.

@bkjones
Created July 27, 2012 02:24
Show Gist options
  • Save bkjones/3185849 to your computer and use it in GitHub Desktop.
Save bkjones/3185849 to your computer and use it in GitHub Desktop.
my context manager was worse off than I thought :(
Original version ('pre' prints the patched callable before entering the 'with' block, and 'post' does the same inside the 'with' block):
.....pre: <unbound method Client.build_url>
post: <MagicMock name='build_url' id='4321796496'>
.pre: <MagicMock name='build_url' id='4321796496'>
post: <MagicMock name='build_url' id='4321825552'>
.pre: <MagicMock name='build_url' id='4321825552'>
post: <MagicMock name='build_url' id='4321871248'>
.pre: <MagicMock name='build_url' id='4321871248'>
post: <MagicMock name='build_url' id='4321904656'>
.pre: <MagicMock name='build_url' id='4321904656'>
post: <MagicMock name='build_url' id='4321938640'>
.pre: <MagicMock name='build_url' id='4321938640'>
post: <MagicMock name='build_url' id='4321989328'>
.pre: <MagicMock name='build_url' id='4321989328'>
post: <MagicMock name='build_url' id='4322023568'>
.pre: <MagicMock name='build_url' id='4322023568'>
post: <MagicMock name='build_url' id='4322066064'>
.pre: <MagicMock name='build_url' id='4322066064'>
post: <MagicMock name='build_url' id='4324340944'>
Updated version:
.....pre: <unbound method Client.build_url>
post: <MagicMock name='build_url' id='4321796496'>
.pre: <unbound method Client.build_url>
post: <MagicMock name='build_url' id='4321829584'>
.pre: <unbound method Client.build_url>
post: <MagicMock name='build_url' id='4321866768'>
.pre: <unbound method Client.build_url>
post: <MagicMock name='build_url' id='4321903952'>
.pre: <unbound method Client.build_url>
post: <MagicMock name='build_url' id='4321937040'>
.pre: <unbound method Client.build_url>
post: <MagicMock name='build_url' id='4321970576'>
.pre: <unbound method Client.build_url>
post: <MagicMock name='build_url' id='4322008400'>
.pre: <unbound method Client.build_url>
post: <MagicMock name='build_url' id='4322050448'>
.pre: <unbound method Client.build_url>
post: <MagicMock name='build_url' id='4322084240'>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment