Exemple #1
0
def test_case():
    with patch('sample_project.project.sample_class') as mock:
        mock().get_object_to_slice.return_value = ['Context Manager']
        print("Inside Context Manager")
        print("sample_method result: ", project.sample_method())
        print("sample_class object: ", project.sample_class)

    print("---")
    print("Outside of Context Manager")
    print("sample_method result: ", project.sample_method())
    print("sample_class object: ", project.sample_class)
Exemple #2
0
from sample_project import project


class MonkeyPatchClass():
    def get_object_to_slice(self):
        return ['Monkey Patch is cool']


print("Before Monkey Patch")
print("sample_method result: ", project.sample_method())
print("sample_class object: ", project.sample_class)

project.sample_class = MonkeyPatchClass

print("---")
print("After Monkey Patch")
print("sample_method result: ", project.sample_method())
print("sample_class object: ", project.sample_class)
Exemple #3
0
def test_case(mock):
    mock().get_object_to_slice.return_value = ['Decorator']
    print("Mock")
    print("sample_method result: ", project.sample_method())
    print("sample_class object: ", project.sample_class)