Last active
February 3, 2019 01:11
-
-
Save ryanermita/4490fb581b6e3501b44c12cf806ef438 to your computer and use it in GitHub Desktop.
A simple demonstration with regards to autospeccing caveat.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from unittest.mock import patch | |
class MyDummyClass: | |
def __init__(self): | |
self.my_dummy_attribute = "yey!" | |
def test_dummy_function(self): | |
return "hello" | |
class TestAutoSpec(unittest.TestCase): | |
@patch('test_func.MyDummyClass', autospec=True) | |
def test_autospec_function(self, mock_dummy_class): | |
self.assertTrue(hasattr(mock_dummy_class, "test_dummy_function")) | |
@patch('test_func.MyDummyClass', autospec=True) | |
def test_autospec_attribute(self, mock_dummy_class): | |
self.assertTrue(hasattr(mock_dummy_class, "test_dummy_attribute")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment