from bs4 import BeautifulSoup


def collect_warning_messages_from_report(html_file):
    """
    Collect all warning messages from the given HTML report.

    Parameters
    ----------
    html_file : str
        Path to the HTML report file on disk.

    Returns
    -------
    warnings_text : list of str
        The list of collected warnings.
    """
    with open(html_file, 'r') as htmlf:
        soup = BeautifulSoup(htmlf.read(), 'html.parser')

    warnings_text = []
    for div in soup.findAll("div", {"class": "output_stderr"}):

        # we collect the text in the <pre> tags after the standard error,
        # and split the lines; we only keep the lines that contain 'Warning:'
        for pre in div.findAll("pre"):
            warnings_msgs = pre.text.splitlines()
            warnings_msgs = [msg for msg in warnings_msgs if 'Warning:' in msg]
            warnings_text.extend(warnings_msgs)

    return warnings_text