diff --git a/HACKING.rst b/HACKING.rst index a74ff73349..1083075467 100644 --- a/HACKING.rst +++ b/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. diff --git a/tempest/hacking/checks.py b/tempest/hacking/checks.py index 4c1c107651..2adc98e323 100644 --- a/tempest/hacking/checks.py +++ b/tempest/hacking/checks.py @@ -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)