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
diff --git a/HACKING.rst b/HACKING.rst
index a74ff73..1083075 100644
--- a/HACKING.rst
+++ b/HACKING.rst
@@ -9,8 +9,8 @@
------------------------------
- [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 @@
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 4c1c107..2adc98e 100644
--- a/tempest/hacking/checks.py
+++ b/tempest/hacking/checks.py
@@ -21,6 +21,7 @@
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 @@
"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)