This Engineering Notebook post discusses conventions for unit testing. It continues a discussion in PR #3532 <https://github.com/leo-editor/leo-editor/pull/3532>. This post will be pre-writing for an info item.
FĂ©lix asked about the difference between assert and self.assertX (self.assertEqual, etc.) The two are not equivalent, but the choice between the two typically matters only when either assert fails :-) Previously, I thought unit tests should always use one or the other. Now, I use whatever is most convenient. The self.assertEqual method provides more helpful messages than assert, but I usually use g.printObj for real debugging. In particular, g.printObj(g.splitLines(aString)) provides a much better dump than assertEqual. *Notes* All Leo devs should remember to use *g.printObj* for debugging. g.printObj prints the result of *g.objToString*, which defaults to *pprint.pformat*. But objToString uses superior bespoke code in most cases. The self.assertX methods do *not *report their failures when run with pytest: stdout gets sent to dev/null, but a command-line option can override this behavior. The *LeoUnitTest* class in *leoTest2.py* contains several dump methods. Several test runners call these dumpers automatically when tests fail. I mention this because most dumps do not exist in the final unit tests, but I use the dumps while developing the tests. Edward -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/988bfca6-c482-4973-ada8-e8a4c0a3b5b8n%40googlegroups.com.