Redirecting stderr

Hi,
I am trying to run a mimics script in the background and I want to redirect the standard output and the errors to a file. I am able to redirect stdout to a file, but I have no such luck with stderr:

import sys
sys.stdout = open("stdout.txt", "w") 
print("Test standard output") # This works in mimics
sys.stderr = open("stderr.txt", "w")
raise ValueError("Test error") # This does not work in mimics

When I print something, it does not appear in the console as expected, and the line is written to the file (after flushing).
However, when I induce an error, the error still appears on the console even though the stderr should have been redirected to the file. Does mimics still intercept stderr somehow? And is there a way to still capture stderr?
I am using an older version of Mimics (21) but I am currently not able to upgrade.

I eventually managed with the following:

import traceback
with open("stderr.txt", "w") as stderr:
    try:
        do_stuff()
        raise ValueError("Test error")
    except:
        stderr.write(traceback.format_exc())

It is not the prettiest solution in my opinion.
If there is a better way to properly redirect stderr with mimics then I’d love to know about it!