blob: 1db1e260420927ed3edd1cfcad5fb0d38b13fda2 [file] [log] [blame]
Attila Fazekas23fdf1d2013-06-09 16:35:23 +02001Tempest Coding Guide
2====================
3
4
Matthew Treinish8b372892012-12-07 17:13:16 -05005Test Data/Configuration
6-----------------------
7- Assume nothing about existing test data
8- Tests should be self contained (provide their own data)
9- Clean up test data at the completion of each test
10- Use configuration files for values that will vary by environment
11
12
13General
14-------
15- Put two newlines between top-level code (funcs, classes, etc)
16- Put one newline between methods in classes and anywhere else
17- Long lines should be wrapped in parentheses
18 in preference to using a backslash for line continuation.
19- Do not write "except:", use "except Exception:" at the very least
20- Include your name with TODOs as in "#TODO(termie)"
21- Do not name anything the same name as a built-in or reserved word Example::
22
23 def list():
24 return [1, 2, 3]
25
26 mylist = list() # BAD, shadows `list` built-in
27
28 class Foo(object):
29 def list(self):
30 return [1, 2, 3]
31
32 mylist = Foo().list() # OKAY, does not shadow built-in
33
34Imports
35-------
36- Do not import objects, only modules (*)
37- Do not import more than one module per line (*)
38- Do not make relative imports
39- Order your imports by the full module path
40- Organize your imports according to the following template
41
42Example::
43
44 # vim: tabstop=4 shiftwidth=4 softtabstop=4
45 {{stdlib imports in human alphabetical order}}
46 \n
47 {{third-party lib imports in human alphabetical order}}
48 \n
49 {{tempest imports in human alphabetical order}}
50 \n
51 \n
52 {{begin your code}}
53
54
55Human Alphabetical Order Examples
56---------------------------------
57Example::
58
59 import httplib
60 import logging
61 import random
62 import StringIO
ivan-zhu1feeb382013-01-24 10:14:39 +080063 import testtools
Matthew Treinish8b372892012-12-07 17:13:16 -050064 import time
Matthew Treinish8b372892012-12-07 17:13:16 -050065
66 import eventlet
67 import webob.exc
68
69 import tempest.config
70 from tempest.services.compute.json.limits_client import LimitsClientJSON
71 from tempest.services.compute.xml.limits_client import LimitsClientXML
72 from tempest.services.volume.volumes_client import VolumesClientJSON
73 import tempest.test
74
75
76Docstrings
77----------
78Example::
79
80 """A one line docstring looks like this and ends in a period."""
81
82
83 """A multi line docstring has a one-line summary, less than 80 characters.
84
85 Then a new paragraph after a newline that explains in more detail any
86 general information about the function, class or method. Example usages
87 are also great to have here if it is a complex class for function.
88
89 When writing the docstring for a class, an extra line should be placed
90 after the closing quotations. For more in-depth explanations for these
91 decisions see http://www.python.org/dev/peps/pep-0257/
92
93 If you are going to describe parameters and return values, use Sphinx, the
94 appropriate syntax is as follows.
95
96 :param foo: the foo parameter
97 :param bar: the bar parameter
98 :returns: return_type -- description of the return value
99 :returns: description of the return value
100 :raises: AttributeError, KeyError
101 """
102
103
104Dictionaries/Lists
105------------------
106If a dictionary (dict) or list object is longer than 80 characters, its items
107should be split with newlines. Embedded iterables should have their items
108indented. Additionally, the last item in the dictionary should have a trailing
109comma. This increases readability and simplifies future diffs.
110
111Example::
112
113 my_dictionary = {
114 "image": {
115 "name": "Just a Snapshot",
116 "size": 2749573,
117 "properties": {
118 "user_id": 12,
119 "arch": "x86_64",
120 },
121 "things": [
122 "thing_one",
123 "thing_two",
124 ],
125 "status": "ACTIVE",
126 },
127 }
128
129
130Calling Methods
131---------------
132Calls to methods 80 characters or longer should format each argument with
133newlines. This is not a requirement, but a guideline::
134
135 unnecessarily_long_function_name('string one',
136 'string two',
137 kwarg1=constants.ACTIVE,
138 kwarg2=['a', 'b', 'c'])
139
140
141Rather than constructing parameters inline, it is better to break things up::
142
143 list_of_strings = [
144 'what_a_long_string',
145 'not as long',
146 ]
147
148 dict_of_numbers = {
149 'one': 1,
150 'two': 2,
151 'twenty four': 24,
152 }
153
154 object_one.call_a_method('string three',
155 'string four',
156 kwarg1=list_of_strings,
157 kwarg2=dict_of_numbers)
158
159
Matthew Treinish997da922013-03-19 11:44:12 -0400160Test Skips
161----------
162If a test is broken because of a bug it is appropriate to skip the test until
163bug has been fixed. However, the skip message should be formatted so that
164Tempest's skip tracking tool can watch the bug status. The skip message should
165contain the string 'Bug' immediately followed by a space. Then the bug number
166should be included in the message '#' in front of the number.
167
168Example::
169
170 @testtools.skip("Skipped until the Bug #980688 is resolved")
171
172
Matthew Treinish89273ee2013-02-12 13:52:09 -0500173openstack-common
174----------------
175
176A number of modules from openstack-common are imported into the project.
177
178These modules are "incubating" in openstack-common and are kept in sync
179with the help of openstack-common's update.py script. See:
180
181 http://wiki.openstack.org/CommonLibrary#Incubation
182
183The copy of the code should never be directly modified here. Please
184always update openstack-common first and then run the script to copy
185the changes across.
186
187
Matthew Treinish8b372892012-12-07 17:13:16 -0500188OpenStack Trademark
189-------------------
190
Matthew Treinish89273ee2013-02-12 13:52:09 -0500191OpenStack is a registered trademark of the OpenStack Foundation, and uses the
Matthew Treinish8b372892012-12-07 17:13:16 -0500192following capitalization:
193
194 OpenStack
195
196
197Commit Messages
198---------------
199Using a common format for commit messages will help keep our git history
200readable. Follow these guidelines:
201
202 First, provide a brief summary (it is recommended to keep the commit title
203 under 50 chars).
204
205 The first line of the commit message should provide an accurate
206 description of the change, not just a reference to a bug or
207 blueprint. It must be followed by a single blank line.
208
209 If the change relates to a specific driver (libvirt, xenapi, qpid, etc...),
210 begin the first line of the commit message with the driver name, lowercased,
211 followed by a colon.
212
213 Following your brief summary, provide a more detailed description of
214 the patch, manually wrapping the text at 72 characters. This
215 description should provide enough detail that one does not have to
216 refer to external resources to determine its high-level functionality.
217
218 Once you use 'git review', two lines will be appended to the commit
219 message: a blank line followed by a 'Change-Id'. This is important
220 to correlate this commit with a specific review in Gerrit, and it
221 should not be modified.
222
223For further information on constructing high quality commit messages,
224and how to split up commits into a series of changes, consult the
225project wiki:
226
227 http://wiki.openstack.org/GitCommitMessages