How can I document my tests, only my tests?
I document my unittest with Sphinx.
My setup is as followed:
class MyTestWrapper1(unittest.Testcase)
def test_general_setup()
class MyTestWrapper2(MyTestWrapper1)
def test_general_tear_down()
class TheUsedTest1(MyTestWrapper2)
def test_specific_test()
As we can see the parent is Unittest.TestCase and all is derived by TheUsedTes1.
Now I'm going to document the class TheUsedTest1
.
I would like to have all the member functions starting with test_
shown in the HTML output.
To archive that I've used the option :inherited-members:
which actually displays all the test_*
members. But it also displays ALL OTHER member functions from unittest too.
.. automodule:: TheUsedTes1
:members:
:inherited-members:
I've tried to add to my conf.py following snippet. It should skip special parts.
def maybe_skip_member(app, what, name: str, obj, skip, options):
print(name, file=sys.stderr, end='')
if name.startswith('test_'):
print(".. OK", file=sys.stderr)
return False
else:
print(".. nope", file=sys.stderr)
return True
def setup(app):
app.connect('autodoc-skip-member', maybe_skip_member)
But it does not work as expected. Every object which is iterated is killed, if it does not start with test_
. How ever, if the iteration runs over TheUsedTest1
it's killed, and any member function is not respected. So it never reaches the members which should be documented.