This Engineering Notebook post discusses conventions for unit testing. It continues a discussion in PR #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
This Engineering Notebook post discusses conventions for unit testing. It continues a discussion in PR #3532. This post will be pre-writing for an info item.