def METHOD_NAME(pyfile, target, run, redirect_mode):
    @pyfile
    def code_to_debug():
        import debuggee
        import sys
        debuggee.setup()
        sys.stdout.write("line\n")
        ()  # @wait_for_output
    with debug.Session() as session:
        if redirect_mode == "redirectOutput":
            session.config["redirectOutput"] = True
        elif redirect_mode == "internalConsole":
            session.config["console"] = "internalConsole"
        else:
            raise AssertionError("Unexpected: " + redirect_mode)
        with run(session, target(code_to_debug)):
            session.set_breakpoints(code_to_debug, all)
        stop = session.wait_for_stop()
        session.request(
            "evaluate",
            {
                "expression": "sys.stdout.write('evaluated\\n')",
                "frameId": stop.frame_id,
                "context": "repl",
            },
        )
        session.request_continue()
    assert session.output("stdout") == "line\nevaluated\n"