def METHOD_NAME(compiler, python_subprocess):
    mod = compiler.compile_module("""
        #define MODE_READ_ONLY 0
        #define MODE_USE_AFTER_FREE 1
        HPyDef_METH(f, "f", HPyFunc_VARARGS)
        static HPy f_impl(HPyContext *ctx, HPy self, const HPy *args, size_t nargs)
        {
            HPy type;
            int mode;
            const char *name;
            char *buffer;
            // parse arguments
            if (nargs != 2) {
                HPyErr_SetString(ctx, ctx->h_TypeError, "expected exactly 2 arguments");
                return HPy_NULL;
            }
            mode = HPyLong_AsLong(ctx, args[0]);
            if (mode < 0) {
                HPyErr_Clear(ctx);
                HPyErr_SetString(ctx, ctx->h_ValueError, "invalid test mode");
                return HPy_NULL;
            }
            type = mode == 1 ? HPy_Dup(ctx, args[1]) : args[1];
            name = HPyType_GetName(ctx, type);
            if (name == NULL)
                return HPy_NULL;
            switch (mode) {
            case MODE_READ_ONLY:
                // write to read-only memory
                buffer = (char *)name;
                buffer[0] = 'h';
                break;
            case MODE_USE_AFTER_FREE:
                // will cause use after handle was closed
                HPy_Close(ctx, type);
                break;
            }
            return HPyUnicode_FromString(ctx, name);
        }
        @EXPORT(f)
        @INIT
    """)
    result = python_subprocess.run(mod, "mod.f(0, 'hello')")
    assert result.returncode != 0
    assert "HPyType_GetName arg must be a type" in result.stderr.decode("utf-8")
    result = python_subprocess.run(mod, "mod.f(0, str)")
    assert result.returncode != 0
    result = python_subprocess.run(mod, "mod.f(1, str)")
    assert result.returncode != 0