Create documentation for tests

Generate documentation for each test from its docstring.

The sphinx-apidoc tool is used to generate the .rst
files necessary for the generation of the documentation.

When the documentation is being build only functions that
start with "test" are passed to the resulting documentation.

Change-Id: I1878f67e10df9bb1f8289beda8e59a56b5057fe4
This commit is contained in:
Lukas Piwowarski 2020-06-15 17:16:15 +02:00
parent 24961f6244
commit a9055010fc
6 changed files with 62 additions and 6 deletions

View File

@ -24,6 +24,7 @@
import os import os
import subprocess import subprocess
import sys
# Build the plugin registry # Build the plugin registry
def build_plugin_registry(app): def build_plugin_registry(app):
@ -31,16 +32,20 @@ def build_plugin_registry(app):
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
subprocess.call(['tools/generate-tempest-plugins-list.sh'], cwd=root_dir) subprocess.call(['tools/generate-tempest-plugins-list.sh'], cwd=root_dir)
def autodoc_skip_member_handler(app, what, name, obj, skip, options):
return skip or (what == "class" and not name.startswith("test"))
def setup(app): def setup(app):
app.connect('autodoc-skip-member', autodoc_skip_member_handler)
if os.getenv('GENERATE_TEMPEST_PLUGIN_LIST', 'true').lower() == 'true': if os.getenv('GENERATE_TEMPEST_PLUGIN_LIST', 'true').lower() == 'true':
app.connect('builder-inited', build_plugin_registry) app.connect('builder-inited', build_plugin_registry)
# If extensions (or modules to document with autodoc) are in another directory, # If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the # add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here. # documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.')) # sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('../../tempest'))
sys.path.insert(0, os.path.abspath('../../tempest/api'))
# -- General configuration ----------------------------------------------------- # -- General configuration -----------------------------------------------------
@ -204,3 +209,10 @@ latex_documents = [
('index', 'doc-tempest.tex', u'Tempest Testing Project', ('index', 'doc-tempest.tex', u'Tempest Testing Project',
u'OpenStack Foundation', 'manual'), u'OpenStack Foundation', 'manual'),
] ]
latex_use_xindy = False
latex_elements = {
'maxlistdepth': 20,
'printindex': '\\footnotesize\\raggedright\\printindex'
}

View File

@ -56,6 +56,13 @@ Supported OpenStack Releases and Python Versions
supported_version supported_version
Description of Tests
--------------------
.. toctree::
:maxdepth: 2
tests/modules
For Contributors For Contributors
================ ================

View File

@ -0,0 +1,21 @@
Description of Tests
====================
OpenStack Services Integration Tests
------------------------------------
.. toctree::
:maxdepth: 2
scenario/modules
OpenStack Services API Tests
----------------------------
.. toctree::
:maxdepth: 2
compute/modules
identity/modules
image/modules
network/modules
object_storage/modules
volume/modules

View File

@ -62,7 +62,7 @@ class FloatingIPAdminTestJSON(base.BaseAdminNetworkTest):
This test performs below operations: This test performs below operations:
1. Create couple floating ips for admin and non-admin users. 1. Create couple floating ips for admin and non-admin users.
2. Verify if admin can access all floating ips including other user 2. Verify if admin can access all floating ips including other user
and non-admin user can only access its own floating ips. and non-admin user can only access its own floating ips.
""" """
# Create floating ip from admin user # Create floating ip from admin user
floating_ip_admin = self.admin_floating_ips_client.create_floatingip( floating_ip_admin = self.admin_floating_ips_client.create_floatingip(

View File

@ -124,7 +124,7 @@ def idempotent_id(id):
def decorator(f): def decorator(f):
f = testtools.testcase.attr('id-%s' % id)(f) f = testtools.testcase.attr('id-%s' % id)(f)
if f.__doc__: if f.__doc__:
f.__doc__ = 'Test idempotent id: %s\n%s' % (id, f.__doc__) f.__doc__ = 'Test idempotent id: %s\n\n%s' % (id, f.__doc__)
else: else:
f.__doc__ = 'Test idempotent id: %s' % id f.__doc__ = 'Test idempotent id: %s' % id
return f return f

18
tox.ini
View File

@ -282,15 +282,31 @@ deps =
-r{toxinidir}/requirements.txt -r{toxinidir}/requirements.txt
-r{toxinidir}/doc/requirements.txt -r{toxinidir}/doc/requirements.txt
commands = commands =
sphinx-apidoc -f -o doc/source/tests/compute tempest/api/compute
sphinx-apidoc -f -o doc/source/tests/identity tempest/api/identity
sphinx-apidoc -f -o doc/source/tests/image tempest/api/image
sphinx-apidoc -f -o doc/source/tests/network tempest/api/network
sphinx-apidoc -f -o doc/source/tests/object_storage tempest/api/object_storage
sphinx-apidoc -f -o doc/source/tests/scenario tempest/scenario
sphinx-apidoc -f -o doc/source/tests/volume tempest/api/volume
rm -rf doc/build rm -rf doc/build
sphinx-build -W -b html doc/source doc/build/html sphinx-build -W -b html doc/source doc/build/html
whitelist_externals = rm whitelist_externals =
rm
[testenv:pdf-docs] [testenv:pdf-docs]
deps = {[testenv:docs]deps} deps = {[testenv:docs]deps}
whitelist_externals = whitelist_externals =
rm
make make
commands = commands =
sphinx-apidoc -f -o doc/source/tests/compute tempest/api/compute
sphinx-apidoc -f -o doc/source/tests/identity tempest/api/identity
sphinx-apidoc -f -o doc/source/tests/image tempest/api/image
sphinx-apidoc -f -o doc/source/tests/network tempest/api/network
sphinx-apidoc -f -o doc/source/tests/object_storage tempest/api/object_storage
sphinx-apidoc -f -o doc/source/tests/scenario tempest/scenario
sphinx-apidoc -f -o doc/source/tests/volume tempest/api/volume
sphinx-build -W -b latex doc/source doc/build/pdf sphinx-build -W -b latex doc/source doc/build/pdf
make -C doc/build/pdf make -C doc/build/pdf