Update tempest hacking regarding unit tests
This commit just updates some of the hacking documentation around unit tests. It also adds a new hacking rule to ensure that setUpClass isn't used for the unit tests. Partially implements bp unit-tests Change-Id: Ie8b1c9f1312a467265d53bc28ee905fa1b5fbb53
This commit is contained in:
parent
3ba85a2ae5
commit
ecf212c49f
14
HACKING.rst
14
HACKING.rst
@ -9,8 +9,8 @@ Tempest Specific Commandments
|
||||
------------------------------
|
||||
|
||||
- [T102] Cannot import OpenStack python clients in tempest/api tests
|
||||
- [T103] tempest/tests is deprecated
|
||||
- [T104] Scenario tests require a services decorator
|
||||
- [T105] Unit tests cannot use setUpClass
|
||||
|
||||
Test Data/Configuration
|
||||
-----------------------
|
||||
@ -192,3 +192,15 @@ Sample Configuration File
|
||||
The sample config file is autogenerated using a script. If any changes are made
|
||||
to the config variables in tempest then the sample config file must be
|
||||
regenerated. This can be done running the script: tools/generate_sample.sh
|
||||
|
||||
Unit Tests
|
||||
----------
|
||||
Unit tests are a separate class of tests in tempest. They verify tempest
|
||||
itself, and thus have a different set of guidelines around them:
|
||||
|
||||
1. They can not require anything running externally. All you should need to
|
||||
run the unit tests is the git tree, python and the dependencies installed.
|
||||
This includes running services, a config file, etc.
|
||||
|
||||
2. The unit tests cannot use setUpClass, instead fixtures and testresources
|
||||
should be used for shared state between tests.
|
||||
|
@ -21,6 +21,7 @@ PYTHON_CLIENTS = ['cinder', 'glance', 'keystone', 'nova', 'swift', 'neutron']
|
||||
|
||||
PYTHON_CLIENT_RE = re.compile('import (%s)client' % '|'.join(PYTHON_CLIENTS))
|
||||
TEST_DEFINITION = re.compile(r'^\s*def test.*')
|
||||
SETUPCLASS_DEFINITION = re.compile(r'^\s*def setUpClass')
|
||||
SCENARIO_DECORATOR = re.compile(r'\s*@.*services\(')
|
||||
|
||||
|
||||
@ -52,6 +53,14 @@ def scenario_tests_need_service_tags(physical_line, filename,
|
||||
"T104: Scenario tests require a service decorator")
|
||||
|
||||
|
||||
def no_setupclass_for_unit_tests(physical_line, filename):
|
||||
if 'tempest/tests' in filename:
|
||||
if SETUPCLASS_DEFINITION.match(physical_line):
|
||||
return (physical_line.find('def'),
|
||||
"T105: setUpClass can not be used with unit tests")
|
||||
|
||||
|
||||
def factory(register):
|
||||
register(import_no_clients_in_api)
|
||||
register(scenario_tests_need_service_tags)
|
||||
register(no_setupclass_for_unit_tests)
|
||||
|
Loading…
x
Reference in New Issue
Block a user