Skip to content
Open
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
11 changes: 5 additions & 6 deletions pytest_doctestplus/sphinx/doctestplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,26 @@
tests.
"""
import re
from docutils.nodes import literal_block
from docutils.parsers.rst import Directive

from sphinx.util.docutils import SphinxDirective

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


class DoctestSkipDirective(Directive):
class DoctestSkipDirective(SphinxDirective):
has_content = True

def run(self):
# Check if there is any valid argument, and skip it. Currently only
# 'win32' is supported.
if re.match('win32', self.content[0]):
if len(self.content) > 0 and re.match("win32", self.content[0]):
self.content = self.content[2:]
code = '\n'.join(self.content)
return [literal_block(code, code)]

nodes = self.parse_content_to_nodes()
return nodes

class DoctestOmitDirective(NoRunDirective):
has_content = True
Expand Down
38 changes: 38 additions & 0 deletions tests/docs/skip_some.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,41 @@ Code in doctest should run only if version condition is satisfied:
.. doctest-requires:: pytest>=1.0 pytest>=2.0

>>> import pytest


Combined Directives
===================


Marking code with two directives:

.. deprecated:: 1.0
.. doctest-requires:: numpy<=0.1

>>> 1 + 3
2


The order should not matter:

.. doctest-requires:: numpy<=0.1
.. deprecated:: 1.0

>>> 1 + 3
2

Try two doctestplus directives:

.. doctest-requires:: sys
.. doctest-skip::

>>> 1 + 3
2

Switch the order and it should still not run:

.. doctest-skip::
.. doctest-requires:: sys

>>> 1 + 3
2