Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage extension crashes when module contents are not found #11678

Closed
aragilar opened this issue Sep 6, 2023 · 2 comments · Fixed by #11702
Closed

coverage extension crashes when module contents are not found #11678

aragilar opened this issue Sep 6, 2023 · 2 comments · Fixed by #11702

Comments

@aragilar
Copy link

aragilar commented Sep 6, 2023

Describe the bug

It appears if the coverage extension fails to find the module (or simply is empty, then it crashes because it divides by the number of objects in that module, which is 0.

Traceback (most recent call last):
  File "/home/aragilar/Projects/DC/dcldap/.tox/docs/lib/python3.11/site-packages/sphinx/cmd/build.py", line 298, in build_main
    app.build(args.force_all, args.filenames)
  File "/home/aragilar/Projects/DC/dcldap/.tox/docs/lib/python3.11/site-packages/sphinx/application.py", line 355, in build
    self.builder.build_update()
  File "/home/aragilar/Projects/DC/dcldap/.tox/docs/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 290, in build_update
    self.build(['__all__'], to_build)
  File "/home/aragilar/Projects/DC/dcldap/.tox/docs/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 363, in build
    self.write(docnames, list(updated_docnames), method)
  File "/home/aragilar/Projects/DC/dcldap/.tox/docs/lib/python3.11/site-packages/sphinx/ext/coverage.py", line 110, in write
    self.write_py_coverage()
  File "/home/aragilar/Projects/DC/dcldap/.tox/docs/lib/python3.11/site-packages/sphinx/ext/coverage.py", line 310, in write_py_coverage
    self._write_py_statistics(sys.stdout)
  File "/home/aragilar/Projects/DC/dcldap/.tox/docs/lib/python3.11/site-packages/sphinx/ext/coverage.py", line 295, in _write_py_statistics
    f'{100 * len(all_documented_objects) / len(all_objects):.2f}%',
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
ZeroDivisionError: division by zero

How to Reproduce

Running the coverage builder on an empty project should reproduce this.

Environment Information

# Platform:         linux; (Linux-6.4.0-4-amd64-x86_64-with-glibc2.37)
# Sphinx version:   7.2.5
# Python version:   3.11.5 (CPython)
# Docutils version: 0.20.1
# Jinja2 version:   3.1.2
# Pygments version: 2.16.1

Sphinx extensions

# Loaded extensions:
#   sphinx.ext.mathjax (7.2.5)
#   alabaster (0.7.13)
#   sphinxcontrib.applehelp (1.0.7)
#   sphinxcontrib.devhelp (1.0.5)
#   sphinxcontrib.htmlhelp (2.0.4)
#   sphinxcontrib.serializinghtml (1.1.9)
#   sphinxcontrib.qthelp (1.0.6)
#   sphinx.ext.autodoc.preserve_defaults (7.2.5)
#   sphinx.ext.autodoc.type_comment (7.2.5)
#   sphinx.ext.autodoc.typehints (7.2.5)
#   sphinx.ext.autodoc (7.2.5)
#   sphinx.ext.doctest (7.2.5)
#   sphinx.ext.coverage (7.2.5)
#   sphinxcontrib.confluencebuilder (2.2.0)

Additional context

No response

@picnixz
Copy link
Member

picnixz commented Sep 6, 2023

I think 31829a9 is meant to fix this (the PR hasn't landed yet because the bug was probably discovered only now).

cc @stephenfin

@stephenfin
Copy link
Contributor

Yup, I found and fixed that as part of #11592. Feel free to pull that out into its own PR if needed.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants