Skip to content

Instantly share code, notes, and snippets.

@exupero
Created December 12, 2012 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exupero/4267684 to your computer and use it in GitHub Desktop.
Save exupero/4267684 to your computer and use it in GitHub Desktop.
from contextlib import contextmanager
@contextmanager
def assert_change_by(fn, delta):
original = fn()
yield
final = fn()
assert final - original == delta
with assert_change_by(User.objects.count, 1):
add_user()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment