Skip to content
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
10 changes: 6 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,14 @@ of the line here.

.. code-block:: rst

.. doctest-skip-all
.. doctest-skip-all::

>>> import non_existing
>>> non_existing.write_pseudo_code()
All the doctests are skipped in the file below
All the doctests are skipped in the file below

.. code-block::

>>> import non_existing
>>> non_existing.write_pseudo_code()

Skip Unconditionally
^^^^^^^^^^^^^^^^^^^^
Expand Down
23 changes: 15 additions & 8 deletions pytest_doctestplus/sphinx/doctestplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
from docutils.parsers.rst import Directive


class NoRunDirective(Directive):
def run(self):
# Simply do not add any content when this directive is encountered
return []


class DoctestSkipDirective(Directive):
has_content = True

Expand All @@ -26,29 +32,30 @@ def run(self):
return [literal_block(code, code)]


class DoctestOmitDirective(Directive):
class DoctestOmitDirective(NoRunDirective):
has_content = True

def run(self):
# Simply do not add any content when this directive is encountered
return []


class DoctestRequiresDirective(DoctestSkipDirective):
# This is silly, but we really support an unbounded number of
# optional arguments
optional_arguments = 64


class DoctestAllDirective(NoRunDirective):
optional_arguments = 64
has_content = False


def setup(app):

app.add_directive('doctest-requires', DoctestRequiresDirective)
app.add_directive('doctest-requires-all', DoctestRequiresDirective)
app.add_directive('doctest-requires-all', DoctestAllDirective)
app.add_directive('doctest-skip', DoctestSkipDirective)
app.add_directive('doctest-skip-all', DoctestSkipDirective)
app.add_directive('doctest-skip-all', DoctestAllDirective)
app.add_directive('doctest', DoctestSkipDirective, override=True)
app.add_directive('doctest-remote-data', DoctestSkipDirective)
app.add_directive('doctest-remote-data-all', DoctestSkipDirective)
app.add_directive('doctest-remote-data-all', DoctestAllDirective)
# Code blocks that use this directive will not appear in the generated
# documentation. This is intended to hide boilerplate code that is only
# useful for testing documentation using doctest, but does not actually
Expand Down
20 changes: 20 additions & 0 deletions tests/docs/remotedata_all.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
:orphan:

.. doctest-remote-data-all::

.. _label_to_check_that_no_content_works_probably_unnecessary2:

Some Bad Test Cases
*******************

All of the example code blocks in this file are going to fail if they run. So
if the directive used at the top of this file does not work, then there are
going to be test failures.

Undefined Variables
===================

This one will fail because the variables haven't been defined::

>>> 2 + 3
5
38 changes: 38 additions & 0 deletions tests/docs/requires_all.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
:orphan:

.. doctest-requires-all:: asdfasdfasdf

.. _label_to_check_that_no_content_works_probably_unnecessary:

Some Bad Test Cases
*******************

All of the example code blocks in this file are going to fail if they run. So
if the directive used at the top of this file does not work, then there are
going to be test failures.

Undefined Variables
===================

This one will fail because the variables haven't been defined::

>>> x + y
5

No Such Module
==============

This one will fail because there's (probably) no such module::

>>> import foobar
>>> foobar.baz(42)
0

What???
=======

This one will fail because it's just not valid python::

>>> NOT VALID PYTHON, OKAY?
>>> + 5
10
2 changes: 2 additions & 0 deletions tests/docs/skip_some_remote_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ This codeblock should fail, but is skipped:

.. doctest-remote-data-all::

.. code-block::

>>> 1 + 1
3

Expand Down
3 changes: 3 additions & 0 deletions tests/test_doctestplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ def test_requires_all(testdir):
"""
.. doctest-requires-all:: foobar

.. code-block::
>>> import foobar

This is a narrative line, before another doctest snippet
Expand Down Expand Up @@ -963,6 +964,8 @@ def test_remote_data_all(testdir):

.. doctest-remote-data-all::

.. code-block::

>>> from contextlib import closing
>>> from urllib.request import urlopen
>>> with closing(urlopen('https://www.astropy.org')) as remote:
Expand Down