I am using a function from an imported module within an optimization loop. As a consequence the function gets called 10s or 100s of times. Since this is an optimization, sometimes the test parameters will cause a warning to be raised in the function being called (for example, because they are below a threshold value). I'm ok with these warnings, but I don't need them to appear 100s of times in my terminal. I am fine with manually checking the resulting parameters after the optimization has completed.
Is there some kind context manager that can be used to suppress any calls to logger.warning just for this function call?
An extra wrinkle is that the imported module is using loguru for logging. I'm not sure if that necessitates a different solution or not.