def METHOD_NAME(self, doc: Document, messageRegex):
    messages = check_sanity()
    self.assertTrue(messages.has_error)
    with self.assertLogs() as capture:
        messages.log_messages()
        self.assertEqual(
            capture.records[0].message,
            f"Detected following issue(s) with document #{doc.pk}, titled {doc.title}",
        )
        self.assertRegex(capture.records[1].message, messageRegex)