blob: 2ac766e7cc490e326f2d2e11994e79b7e4075165 [file] [log] [blame]
Attila Fazekas23fdf1d2013-06-09 16:35:23 +02001Tempest Coding Guide
2====================
3
Joe Gordon1374f882013-07-12 17:00:34 +01004- Step 1: Read the OpenStack Style Commandments
5 https://github.com/openstack-dev/hacking/blob/master/HACKING.rst
6- Step 2: Read on
7
8Tempest Specific Commandments
9------------------------------
10
11[T101] If a test is broken because of a bug it is appropriate to skip the test until
12bug has been fixed. However, the skip message should be formatted so that
13Tempest's skip tracking tool can watch the bug status. The skip message should
14contain the string 'Bug' immediately followed by a space. Then the bug number
15should be included in the message '#' in front of the number.
16
17Example::
18
19 @testtools.skip("Skipped until the Bug #980688 is resolved")
20
21- [T102] Cannot import OpenStack python clients in tempest/api tests
22- [T103] tempest/tests is deprecated
Attila Fazekas23fdf1d2013-06-09 16:35:23 +020023
Matthew Treinish8b372892012-12-07 17:13:16 -050024Test Data/Configuration
25-----------------------
26- Assume nothing about existing test data
27- Tests should be self contained (provide their own data)
28- Clean up test data at the completion of each test
29- Use configuration files for values that will vary by environment
30
31
Attila Fazekas10fd63d2013-07-04 18:38:21 +020032Exception Handling
33------------------
34According to the ``The Zen of Python`` the
35 ``Errors should never pass silently.``
36Tempest usually runs in special environment (jenkins gate jobs), in every
37error or failure situation we should provide as much error related
38information as possible, because we usually do not have the chance to
39investigate the situation after the issue happened.
40
41In every test case the abnormal situations must be very verbosely explained,
42by the exception and the log.
43
44In most cases the very first issue is the most important information.
45
46Try to avoid using ``try`` blocks in the test cases, both the ``except``
47and ``finally`` block could replace the original exception,
48when the additional operations leads to another exception.
49
50Just letting an exception to propagate, is not bad idea in a test case,
51 at all.
52
53Try to avoid using any exception handling construct which can hide the errors
54origin.
55
56If you really need to use a ``try`` block, please ensure the original
57exception at least logged. When the exception is logged you usually need
58to ``raise`` the same or a different exception anyway.
59
60Use the ``self.assert*`` methods provided by the unit test framework
61 the signal failures early.
62
63Avoid using the ``self.fail`` alone, it's stack trace will signal
64 the ``self.fail`` line as the origin of the error.
65
66Avoid constructing complex boolean expressions for assertion.
67The ``self.assertTrue`` or ``self.assertFalse`` will just tell you the
68single boolean, and you will not know anything about the values used in
69the formula. Most other assert method can include more information.
70For example ``self.assertIn`` can include the whole set.
71
72If the test case fails you can see the related logs and the information
73carried by the exception (exception class, backtrack and exception info).
74This and the service logs are your only guide to find the root cause of flaky
75issue.
76
77
Matthew Treinish997da922013-03-19 11:44:12 -040078