ENB: info re unit tests

21 views
Skip to first unread message

Edward K. Ream

unread,
Sep 3, 2023, 7:54:12 AM9/3/23
to leo-editor

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

Edward K. Ream

unread,
Sep 3, 2023, 9:10:03 AM9/3/23
to leo-e...@googlegroups.com
On Sun, Sep 3, 2023 at 6:54 AM Edward K. Ream <edre...@gmail.com> wrote:

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.


See #3534.

Edward
Reply all
Reply to author
Forward
0 new messages