Skip to content

Instantly share code, notes, and snippets.

@kyleconroy
Forked from RobSpectre/test.py
Created April 20, 2012 21:40
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 kyleconroy/2432069 to your computer and use it in GitHub Desktop.
Save kyleconroy/2432069 to your computer and use it in GitHub Desktop.
Failure to patch accurately
import unittest
from mock import patch
class Class:
def __init__(self):
self.foo = 'bar'
class TestClass(unittest.TestCase):
@patch('__main__.Class')
def test_class(self, MockClass):
mock_class = MockClass.return_value
mock_class.foo = 'THIS IS NOT BAR ANYMORE, SNACKY.'
self.assertTrue(mock_class.foo != 'bar')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment