Added pyversion option for doctest (issue 3303)

Code, tests and documentation.
This commit is contained in:
Marco Buttu 2017-01-15 10:27:34 +01:00
parent 19298dec33
commit 960f889a2c
3 changed files with 14 additions and 5 deletions

View File

@ -63,7 +63,7 @@ a comma-separated list of group names.
default set of flags is specified by the :confval:`doctest_default_flags`
configuration variable.
This directive supports two options:
This directive supports three options:
* ``hide``, a flag option, hides the doctest block in other builders. By
default it is shown as a highlighted doctest block.
@ -73,6 +73,17 @@ a comma-separated list of group names.
explicit flags per example, with doctest comments, but they will show up in
other builders too.)
* ``pyversion``, a string option, can be used to specify the required Python
version for the example to be tested. For instance, in the following case
the example will be tested only for Python versions greather than 3.3::
.. doctest::
:pyversion: > 3.3
The supported operands are ``<``, ``<=``, ``==``, ``>=``, and ``>``.
.. versionadded:: 1.5
Note that like with standard doctests, you have to use ``<BLANKLINE>`` to
signal a blank line in the expected output. The ``<BLANKLINE>`` is removed
when building presentation output (HTML, LaTeX etc.).

View File

@ -133,7 +133,7 @@ class TestDirective(Directive):
This function is meant to be used to evaluate the doctest :pyversion:
option. For instance, if the doctest directive provides the option
:pyversion: >= 3.3, then we have to check if the running Python version
is greather or equal to 3.3. In that case, operand will be the string
is greather or equal than 3.3. In that case, operand will be the string
'>=' and version the string '3.3'. proper_pyversion() will return True
if the running Python version is >= 3.3, False otherwise.
"""

View File

@ -28,9 +28,7 @@ def test_build(app, status, warning):
def test_pyversion(monkeypatch):
def python_version():
return '3.3'
monkeypatch.setattr(platform, 'python_version', python_version)
monkeypatch.setattr(platform, 'python_version', lambda: '3.3')
td = _TestDirective(*([None] * 9))
assert td.proper_pyversion('<', '3.4') is True
assert td.proper_pyversion('<', '3.2') is False