I have been looking at using Sphinx to document test modules that uses pytest. In the script there are user defined pytest.mark. Is there a way to configure Sphinx or the .rst template file to include the pytest.mark definitions even though they are outside of the docstring?
The sphinx documentation on the use of :regexp: is extremely vague and I have been unable to find a good example that uses it.
Python 2.7.6 Sphinx-build 1.3.3
"""
script: test_sample.py
:Test Description: Simple test to show function of py.test and sphinx doc
:Author: James Brown
Requirement ID: Test1234
"""
import sys
from sys import argv
import re
import pytest
pytestmark = [
pytest.mark.author("jbrown"),
pytest.mark.req("test-001"),
pytest.mark.testtype("Full"),
pytest.mark.mat0]
blah = """
blah
blah
blah
"""
def func(x):
"""
Returns an integer incremented by one
"""
return x + 1
def test_answer():
"""
Checks if value equals 5
"""
assert func(3) == 5
rst file addition
.. exec::
import re
from src.test_samplepytest import pytestmark
attre = re.compile(r"\'(\w+)\'.*\(\'?(\w*)")
for value in pytestmark:
mark = str(value)
att = attre.search(mark)
if att.group(2):
print "{:<10}: {:<15}\n".format(att.group(1),att.group(2))
else:
print "{:<10}: \n".format(att.group(1))'