def METHOD_NAME(output_file_name: Optional[str]) -> Generator[None, None, None]:
    if output_file_name:
        file = open(output_file_name, 'w')
        saved_stdout = sys.stdout
        sys.stdout = file
        try:
            yield
        finally:
            sys.stdout = saved_stdout
            file.close()
    else:
        yield