I'm trying write some unittests for my code which in turn uses a decorator
import unittest
from unittest.mock import patch
from functools import wraps
def decorator(f):
@wraps(f)
def decorated(x):
return f(x+1)
return decorated
@decorator
def get_value(x):
return x
class MyTestCase(unittest.TestCase):
@patch('file.decorator', lambda f: f)
def test_something(self):
result = get_value(1)
self.assertEqual(1, result)
I'm trying to mock the decorated function to just return f and completely bypass the decorator logic part. This is talked about in Overriding decorator during unit test in python but doesn't really work.