From e41b0861513cae7aa6cbbe20b73505ac9ffc12a2 Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Thu, 29 Jun 2017 18:23:34 -0300 Subject: [PATCH] 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 --- tests/topotests/GUIDELINES.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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 -- 2.39.5