We have a centrally defined test case base class that handles a set of things like log capture, mocking time.sleep and setting up requests-mock. We also had a split base test case, with some things using TestCase and some using RequestsMockTestCase. This was a holdover from the transition to requests-mock. We are finally at the point where we don't need the split, so merge TestCase and RequestsMockTest case. Then, update all of the tests to use the new combined base class. Also, replace a use of unittest.skipTest with self.skipTest from the base class. Change-Id: I2cc3e201a5241262e5d102d3de8423c4fb2a8c4a
1.5 KiB
openstacksdk Style Commandments
Read the OpenStack Style Commandments http://docs.openstack.org/developer/hacking/
Indentation
PEP-8 allows for 'visual' indentation. Do not use it. Visual indentation looks like this:
= self.some_method(arg1, arg1,
return_value arg3, arg4)
Visual indentation makes refactoring the code base unneccesarily hard.
Instead of visual indentation, use this:
= self.some_method(
return_value arg1, arg1, arg3, arg4)
That way, if some_method ever needs to be renamed, the only line that needs to be touched is the line with some_method.
Additionaly, if you need to line break at the top of a block, please indent the continuation line an additional 4 spaces, like this:
for val in self.some_method(
arg1, arg1, arg3, arg4):self.do_something_awesome()
Neither of these are 'mandated' by PEP-8. However, they are prevailing styles within this code base.
Unit Tests
Unit tests should be virtually instant. If a unit test takes more than 1 second to run, it is a bad unit test. Honestly, 1 second is too slow.
All unit test classes should subclass openstack.tests.unit.base.TestCase. The base TestCase class takes care of properly creating Connection objects in a way that protects against local environment.
Test cases should use requests-mock to mock out HTTP interactions rather than using mock to mock out object access.