[Python-ideas] Unittest error message failure context lazy creation

francismb francismb at email.de
Sat Aug 26 14:25:41 EDT 2017

Hi all,
while using `unittest` I see the pattern of creating an error message
with the test context for the case that some `assert...` methods fails
(to get a good error message). On the lines:

class Test...(unittest.TestCase):

  longMessage = True

  def test_(self):
    for a, b, c ... in zip(A, B, C, ..):
      * call the function under test and get the result
      msg = "Some headline: {}{} ...".format(a, b, c,..)
      self.assert...(  ,msg)

The `msg` is just used in case the assert fails but its creation takes
time and adds up.

What is the best practice/pattern you use here?

Or, are there ideas to have a lazy mechanism to avoid that creation and
just infer them in the case the assert failed?

Thanks in advance!

More information about the Python-ideas mailing list