def METHOD_NAME(monkeypatch):
    def broken_mkstemp(dir):
        raise RuntimeError
    monkeypatch.setattr(tempfile, "mkstemp", broken_mkstemp)
    try:
        # Cache the charmap to avoid a performance hit the next time
        # somebody tries to use it.
        saved = cm._charmap
        cm._charmap = None
        os.unlink(cm.charmap_file())
        cm.charmap()
    finally:
        cm._charmap = saved