If you need to capture both streams at once, use the parent CaptureStd class:
thon
from transformers.testing_utils import CaptureStd
with CaptureStd() as cs:
    function_that_writes_to_stdout_and_stderr()
print(cs.err, cs.out)