code: def mail_sent_contains_html(self):
      
  
      for email in mail.outbox:
          try:
              html = next(content for content, mime in email.alternatives
                          if mime == 'text/html')
              dom1 = parse_html(html)
              dom2 = parse_html(self.multiline)
  
              assert_in(dom1, dom2)
  
          except AssertionError as exc:
              print("Email did not match", exc)
              # we intentionally eat the exception
              continue
  
          return True
  
      raise AssertionError("No email contained the HTML")
docs: Test that an email contains the HTML (assert HTML in) in the multiline as
      one of its MIME alternatives.
  
      The HTML is normalised by passing through Django's
      :func:`django.test.html.parse_html`.
  
      Example:
  
      .. code-block:: gherkin
  
          And I have sent an email with the following HTML alternative:
          \"\"\"
          <p><strong>Name:</strong> Sir Panda</p>
          <p><strong>Phone:</strong> 0400000000</p>
          <p><strong>Email:</strong> sir.panda@pand.as</p>
          \"\"\"