def METHOD_NAME(pyfile, wait_for_client, is_client_connected, stop_method):
    @pyfile
    def code_to_debug():
        import debuggee
        import debugpy
        import sys
        import time
        from debuggee import backchannel, scratchpad
        # Test different ways of calling configure(). 
        debugpy.configure(qt="none", subProcess=True, python=sys.executable)
        debugpy.configure({"qt": "none", "subProcess": True, "python": sys.executable})
        debugpy.configure({"qt": "none"}, python=sys.executable)
        debuggee.setup()
        _, host, port, wait_for_client, is_client_connected, stop_method = sys.argv
        port = int(port)
        debugpy.listen(address=(host, port))
        if wait_for_client:
            backchannel.send("wait_for_client")
            debugpy.wait_for_client()
        if is_client_connected:
            backchannel.send("is_client_connected")
            while not debugpy.is_client_connected():
                print("looping until is_client_connected()")
                time.sleep(0.1)
        if stop_method == "breakpoint":
            backchannel.send("breakpoint?")
            assert backchannel.receive() == "proceed"
            debugpy.breakpoint()
            print("break")  # @breakpoint
        else:
            scratchpad["paused"] = False
            backchannel.send("loop?")
            assert backchannel.receive() == "proceed"
            while not scratchpad["paused"]:
                print("looping until paused")
                time.sleep(0.1)
    with debug.Session() as session:
        host, port = runners.attach_connect.host, runners.attach_connect.port
        session.config.update({"connect": {"host": host, "port": port}})
        backchannel = session.open_backchannel()
        session.spawn_debuggee(
            [
                code_to_debug,
                host,
                port,
                wait_for_client,
                is_client_connected,
                stop_method,
            ]
        )
        session.wait_for_adapter_socket()
        session.connect_to_adapter((host, port))
        with session.request_attach():
            pass
        if wait_for_client:
            assert backchannel.receive() == "wait_for_client"
        if is_client_connected:
            assert backchannel.receive() == "is_client_connected"
        if stop_method == "breakpoint":
            assert backchannel.receive() == "breakpoint?"
            backchannel.send("proceed")
            session.wait_for_stop(
                expected_frames=[some.dap.frame(code_to_debug, "breakpoint")]
            )
        elif stop_method == "pause":
            assert backchannel.receive() == "loop?"
            backchannel.send("proceed")
            session.request("pause", freeze=False)
            session.wait_for_stop("pause")
            session.scratchpad["paused"] = True
        else:
            pytest.fail(stop_method)
        session.request_continue()