Skip to content

Instantly share code, notes, and snippets.

@wellic
Created October 28, 2021 08:53
Show Gist options
  • Save wellic/3d6e510f13fba4657684ecaeb903c93c to your computer and use it in GitHub Desktop.
Save wellic/3d6e510f13fba4657684ecaeb903c93c to your computer and use it in GitHub Desktop.
import unittest
from functools import wraps
from unittest import mock
def log(*args, **kwargs):
""" Logging function """
def print_debug(*args, **kwargs):
""" Logging function """
log(*args, **kwargs)
print(f" args = {args}\n kwargs = {kwargs}")
def logging_decorator(f):
""" Implement decorator here """
@wraps(f)
def inner(*args, **kwargs):
print(f"\n{f.__name__}:")
print_debug(*args, **kwargs)
return f(*args, **kwargs)
return inner
class TestDecorator(unittest.TestCase):
@mock.patch(f'{__name__}.log')
def test_success(self, mocked_login):
@logging_decorator
def dummy_function(a, b):
return a + b
result = dummy_function(1, b=2)
self.assertEqual(result, 3)
mocked_login.assert_called_once()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment