def insert_before(path, value_to_find, code_to_insert) ->str:
    """Insert code before any occurrence of value.

    Args:
        path: Path to file
        value_to_find: search term.
        code_to_insert: Text to insert before search term.

    Returns: Text of modified file.
    """
    contents = []
    for line in path.open(mode='r'):
        if value_to_find not in line:
            contents.append(line)
            continue
        contents.append(code_to_insert)
        contents.append(line)
    return ''.join(contents)
