I am using loguru.logger.catch() function to log some outputs. Also, I want to deactivate this function when I test my class with pytest. I've tried to use monkey patch but didn't work. How can I handle this situation?
Example Code:
class DividerClass:
@logger.catch
def __init__(self, num1, num2):
self.num1 = num1
self.num2 = num2
if self.num2 == 0:
raise ZeroDivisionError
else:
self.result = self.num1 / self.num2
logger.info(f"DividerClass {self.num1} / {self.num2} = {self.result}")
def test_divider_class_with_zero(monkeypatch):
monkeypatch.setattr(loguru.logger, "catch", lambda x: x)
with pytest.raises(ZeroDivisionError):
DividerClass(0, 0)