From: Rafael Zalamena Date: Thu, 29 Jun 2017 21:23:34 +0000 (-0300) Subject: topotest: add writing tests tips X-Git-Tag: frr-7.1-dev~151^2~293 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=e41b0861513cae7aa6cbbe20b73505ac9ffc12a2;p=matthieu%2Ffrr.git topotest: add writing tests tips Add two tips to help improve test code quality: 1) Store function returns for later inspection 2) Identify what failed using the assert message --- diff --git a/tests/topotests/GUIDELINES.md b/tests/topotests/GUIDELINES.md index 5f745ae7ce..1566705bc1 100644 --- a/tests/topotests/GUIDELINES.md +++ b/tests/topotests/GUIDELINES.md @@ -419,6 +419,34 @@ Requirements: * Tests must be able to run without any interaction. To make sure your test conforms with this, run it without the `-s` parameter. +Tips: + +* Keep results in stack variables, so people inspecting code with `pdb` can + easily print their values. + + Don't do this: + + ```py + assert foobar(router1, router2) + ``` + + Do this instead: + + ```py + result = foobar(router1, router2) + assert result + ``` + +* Use `assert` messages to indicate where the test failed. + + Example: + + ```py + for router in router_list: + # ... + assert condition, 'Router "{}" condition failed'.format(router.name) + ``` + ### Debugging Execution