Skip to content

Instantly share code, notes, and snippets.

@ryanermita
Last active February 3, 2019 01:25
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 ryanermita/febd438af5895f4fe2c0f15dd36bbf83 to your computer and use it in GitHub Desktop.
Save ryanermita/febd438af5895f4fe2c0f15dd36bbf83 to your computer and use it in GitHub Desktop.
A simple test that demonstrate the autospec parameter in @patch decorator.
import unittest
from unittest.mock import patch
class MyDummyClass:
def test_dummy_function(self):
return "hello"
class TestAutoSpec(unittest.TestCase):
@patch('test_func.MyDummyClass', autospec=True)
def test_autospec_true(self, mock_dummy_class):
print(dir(mock_dummy_class))
pass
@patch('test_func.MyDummyClass')
def test_autospec_false(self, mock_dummy_class):
print(dir(mock_dummy_class))
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment