Skip to content

Commit

Permalink
Merge pull request #165 from pllim/testcleanup
Browse files Browse the repository at this point in the history
ENH: Support testcleanup
  • Loading branch information
saimn authored Sep 17, 2021
2 parents 16d6d45 + b8f76c1 commit 96165e3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
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

0 comments on commit 96165e3

Please sign in to comment.