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

ENH: Support testcleanup #165

Merged
merged 1 commit into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ of the directives that this plugin defines are described in the sections below.
.. _doctest directives: https://docs.python.org/3/library/doctest.html#directives
.. _documentation: https://docs.python.org/3/library/doctest.html#directives

Sphinx Doctest Directives
~~~~~~~~~~~~~~~~~~~~~~~~~

You can use ``testsetup`` and ``testcleanup`` in Sphinx RST to run code that is
not visible in rendered document. However, due to how ``pytest-doctestplus``
works, the code within needs to be prepended by ``>>>``. For example::

.. testsetup::

>>> x = 42

.. testcleanup::

>>> del x

Floating Point Comparison
~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
1 change: 1 addition & 0 deletions pytest_doctestplus/sphinx/doctestplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def setup(app):
# useful for testing documentation using doctest, but does not actually
# belong in the documentation itself.
app.add_directive('testsetup', DoctestOmitDirective, override=True)
app.add_directive('testcleanup', DoctestOmitDirective, override=True)

return {'parallel_read_safe': True,
'parallel_write_safe': True}
20 changes: 20 additions & 0 deletions tests/docs/skip_some.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ if they run. Some are not. The intent of this file is to test the directives
that are provided by the `--doctest-rst` option to make sure that the bad ones
get skipped.

.. This will not show in doc but it will run in doctestplus.

.. testsetup::

>>> x = 42

This code will show the value of ``x`` that is set within ``testsetup``::

>>> x
42

.. testcleanup::

>>> x = x + 1

This code will show the value of ``x`` that is set within ``testcleanup``::

>>> x
43

Here's One That Works
=====================

Expand Down