Skip to content

Commit

Permalink
WIP: Sphinx autodoc picks up tasks automatically only if `undoc-membe…
Browse files Browse the repository at this point in the history
…rs` is set (celery#4584)

* Add unit test for celery.contrib.sphinx

Note that this unit test reveals a bug: tasks are documented
automatically (e.g. without explicitly adding a `.. autotask::`
line) only if the `undoc-members` option is set. Try removing
'`undoc-members'` from `autodoc_default_flags` in conf.py, and
the test will fail!

* WIP: Remove undoc-members in test_sphinx
  • Loading branch information
lpsinger authored and auvipy committed Mar 10, 2018
1 parent 85eed30 commit 7726bc7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include TODO
include setup.cfg
include setup.py

recursive-include t *.py
recursive-include t *.py *.rst
recursive-include docs *
recursive-include extra/bash-completion *
recursive-include extra/centos *
Expand Down
10 changes: 10 additions & 0 deletions t/unit/contrib/proj/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import absolute_import, unicode_literals

import os
import sys

extensions = ['celery.contrib.sphinx', 'sphinx.ext.autodoc']
autodoc_default_flags = ['members']
autosummary_generate = True

sys.path.insert(0, os.path.abspath('.'))
1 change: 1 addition & 0 deletions t/unit/contrib/proj/contents.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. automodule:: foo
10 changes: 10 additions & 0 deletions t/unit/contrib/proj/foo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import absolute_import, unicode_literals

from celery import Celery

app = Celery()


@app.task
def bar():
"""This task has a docstring!"""
19 changes: 19 additions & 0 deletions t/unit/contrib/test_sphinx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from __future__ import absolute_import, unicode_literals

import pkg_resources
import pytest

try:
sphinx_build = pkg_resources.load_entry_point(
'sphinx', 'console_scripts', 'sphinx-build')
except pkg_resources.DistributionNotFound:
sphinx_build = None


@pytest.mark.skipif(sphinx_build is None, reason='Sphinx is not installed')
def test_sphinx(tmpdir):
srcdir = pkg_resources.resource_filename(__name__, 'proj')
sphinx_build([srcdir, str(tmpdir)])
with open(tmpdir / 'contents.html', 'r') as f:
contents = f.read()
assert 'This task has a docstring!' in contents

0 comments on commit 7726bc7

Please sign in to comment.