I would like to suppress output using print
from a tested function, while keeping output from the testing function, using a decorator on the testing function, in a safe manner. Essentially:
script.py
def func():
print("script")
This module is called in:
test_script.py
import script
@some_decorator
def test_func():
print("test_script")
script.func()
test_func()
What should some_decorator
be, for test_script
to print without script
? I can import any library as necessary on either of the scripts, preferably from the standard library.
Thanks!
EDIT:
I'm using importlib
to import script.py
, so the import line should be something like this:
import importlib
file_name = "script"
script = importlib.import_module(file_name)