Skip to content

Instantly share code, notes, and snippets.

@cpdean
Forked from anonymous/README.markdown
Created July 3, 2013 00:10
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 cpdean/5914423 to your computer and use it in GitHub Desktop.
Save cpdean/5914423 to your computer and use it in GitHub Desktop.

This is how mock.patch should be used, but I'm having some problems on my own codebase.

It's weird, but in this tiny example everything works just fine...

import boto.s3.connection
creds = {"aws_secret_access_key": "fakes",
"aws_access_key_id": "fakes"}
class DBConnection(object):
def connect(self):
return boto.s3.connection.S3Connection(**creds).get_bucket("something")
boto==2.9.6
mock==1.0.1
nose==1.3.0
import db
def connect():
return db.DBConnection().connect()
import service
from mock import patch
def service_test():
with patch("boto.s3.connection.S3Connection.get_bucket") as c:
service.connect()
c.assert_called_with("something")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment