pytest-doctestplus-0.1.2/0000755000175000017500000000000013212331336014734 5ustar dandan00000000000000pytest-doctestplus-0.1.2/LICENSE.rst0000644000175000017500000000273013160600007016546 0ustar dandan00000000000000Copyright (c) 2011-2017, Astropy Developers All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Astropy Team nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. pytest-doctestplus-0.1.2/setup.cfg0000644000175000017500000000012313212331336016551 0ustar dandan00000000000000[pytest] minversion = 2.8 testpaths = tests [egg_info] tag_build = tag_date = 0 pytest-doctestplus-0.1.2/pytest_doctestplus/0000755000175000017500000000000013212331336020715 5ustar dandan00000000000000pytest-doctestplus-0.1.2/pytest_doctestplus/output_checker.py0000644000175000017500000001576113200423543024324 0ustar dandan00000000000000""" Implements a replacement for `doctest.OutputChecker` that handles certain normalizations of Python expression output. See the docstring on `OutputChecker` for more details. """ import doctest import re import numpy as np import six from six.moves import zip # Much of this code, particularly the parts of floating point handling, is # borrowed from the SymPy project with permission. See licenses/SYMPY.rst # for the full SymPy license. FIX = doctest.register_optionflag('FIX') FLOAT_CMP = doctest.register_optionflag('FLOAT_CMP') IGNORE_OUTPUT = doctest.register_optionflag('IGNORE_OUTPUT') IGNORE_OUTPUT_2 = doctest.register_optionflag('IGNORE_OUTPUT_2') IGNORE_OUTPUT_3 = doctest.register_optionflag('IGNORE_OUTPUT_3') class OutputChecker(doctest.OutputChecker): """ - Removes u'' prefixes on string literals - Ignores the 'L' suffix on long integers - In Numpy dtype strings, removes the leading pipe, i.e. '|S9' -> 'S9'. Numpy 1.7 no longer includes it in display. - Supports the FLOAT_CMP flag, which parses floating point values out of the output and compares their numerical values rather than their string representation. This naturally supports complex numbers as well (simply by comparing their real and imaginary parts separately). """ _original_output_checker = doctest.OutputChecker _str_literal_re = re.compile( r"(\W|^)[uU]([rR]?[\'\"])", re.UNICODE) _byteorder_re = re.compile( r"([\'\"])[|<>]([biufcSaUV][0-9]+)([\'\"])", re.UNICODE) _fix_32bit_re = re.compile( r"([\'\"])([iu])[48]([\'\"])", re.UNICODE) _long_int_re = re.compile( r"([0-9]+)L", re.UNICODE) def __init__(self): # NOTE OutputChecker is an old-style class with no __init__ method, # so we can't call the base class version of __init__ here exp = r'(?:e[+-]?\d+)' got_floats = (r'\s*([+-]?\d+\.\d*{0}?|' r'[+-]?\.\d+{0}?|' r'[+-]?\d+{0}|' r'nan|' r'[+-]?inf)').format(exp) # floats in the 'want' string may contain ellipses want_floats = got_floats + r'(\.{3})?' front_sep = r'\s|[*+-,<=(\[]' back_sep = front_sep + r'|[>j)\]]' fbeg = r'^{}(?={}|$)'.format(got_floats, back_sep) fmidend = r'(?<={}){}(?={}|$)'.format(front_sep, got_floats, back_sep) self.num_got_rgx = re.compile(r'({}|{})'.format(fbeg, fmidend)) fbeg = r'^{}(?={}|$)'.format(want_floats, back_sep) fmidend = r'(?<={}){}(?={}|$)'.format(front_sep, want_floats, back_sep) self.num_want_rgx = re.compile(r'({}|{})'.format(fbeg, fmidend)) def do_fixes(self, want, got): want = re.sub(self._str_literal_re, r'\1\2', want) want = re.sub(self._byteorder_re, r'\1\2\3', want) want = re.sub(self._fix_32bit_re, r'\1\2\3', want) want = re.sub(self._long_int_re, r'\1', want) got = re.sub(self._str_literal_re, r'\1\2', got) got = re.sub(self._byteorder_re, r'\1\2\3', got) got = re.sub(self._fix_32bit_re, r'\1\2\3', got) got = re.sub(self._long_int_re, r'\1', got) return want, got def normalize_floats(self, want, got, flags): """ Alternative to the built-in check_output that also handles parsing float values and comparing their numeric values rather than their string representations. This requires rewriting enough of the basic check_output that, when FLOAT_CMP is enabled, it totally takes over for check_output. """ # Handle the common case first, for efficiency: # if they're string-identical, always return true. if got == want: return True # TODO parse integers as well ? # Parse floats and compare them. If some of the parsed floats contain # ellipses, skip the comparison. matches = self.num_got_rgx.finditer(got) numbers_got = [match.group(1) for match in matches] # list of strs matches = self.num_want_rgx.finditer(want) numbers_want = [match.group(1) for match in matches] # list of strs if len(numbers_got) != len(numbers_want): return False if len(numbers_got) > 0: nw_ = [] for ng, nw in zip(numbers_got, numbers_want): if '...' in nw: nw_.append(ng) continue else: nw_.append(nw) if not np.allclose(float(ng), float(nw), equal_nan=True): return False # replace all floats in the "got" string by those from "wanted". # TODO: can this be done more elegantly? Used to replace all with # '{}' and then format, but this is problematic if the string # contains other curly braces (e.g., from a dict). got = self.num_got_rgx.sub(lambda x: nw_.pop(0), got) # can be used as a special sequence to signify a # blank line, unless the DONT_ACCEPT_BLANKLINE flag is used. if not (flags & doctest.DONT_ACCEPT_BLANKLINE): # Replace in want with a blank line. want = re.sub(r'(?m)^{}\s*?$'.format(re.escape(doctest.BLANKLINE_MARKER)), '', want) # If a line in got contains only spaces, then remove the # spaces. got = re.sub(r'(?m)^\s*?$', '', got) if got == want: return True # This flag causes doctest to ignore any differences in the # contents of whitespace strings. Note that this can be used # in conjunction with the ELLIPSIS flag. if flags & doctest.NORMALIZE_WHITESPACE: got = ' '.join(got.split()) want = ' '.join(want.split()) if got == want: return True # The ELLIPSIS flag says to let the sequence "..." in `want` # match any substring in `got`. if flags & doctest.ELLIPSIS: if doctest._ellipsis_match(want, got): return True # We didn't find any match; return false. return False def check_output(self, want, got, flags): if (flags & IGNORE_OUTPUT or (six.PY2 and flags & IGNORE_OUTPUT_2) or (not six.PY2 and flags & IGNORE_OUTPUT_3)): return True if flags & FIX: want, got = self.do_fixes(want, got) if flags & FLOAT_CMP: return self.normalize_floats(want, got, flags) # Can't use super here because doctest.OutputChecker is not a # new-style class. return self._original_output_checker.check_output( self, want, got, flags) def output_difference(self, want, got, flags): if flags & FIX: want, got = self.do_fixes(want, got) # Can't use super here because doctest.OutputChecker is not a # new-style class. return self._original_output_checker.output_difference( self, want, got, flags) pytest-doctestplus-0.1.2/pytest_doctestplus/plugin.py0000644000175000017500000003556013200423543022575 0ustar dandan00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst """ This plugin provides advanced doctest support and enables the testing of .rst files. """ import six import doctest import fnmatch import imp import os import re import sys import pytest from .output_checker import OutputChecker, FIX # these pytest hooks allow us to mark tests and run the marked tests with # specific command line options. def pytest_addoption(parser): parser.addoption("--doctest-plus", action="store_true", help="enable running doctests with additional " "features not found in the normal doctest " "plugin") parser.addoption("--doctest-rst", action="store_true", help="enable running doctests in .rst documentation") parser.addini("doctest_plus", "enable running doctests with additional " "features not found in the normal doctest plugin") parser.addini("doctest_norecursedirs", "like the norecursedirs option but applies only to doctest " "collection", type="args", default=()) parser.addini("doctest_rst", "Run the doctests in the rst documentation", default=False) # We monkey-patch in our replacement doctest OutputChecker. Not # great, but there isn't really an API to replace the checker when # using doctest.testfile, unfortunately. doctest.OutputChecker = OutputChecker REMOTE_DATA = doctest.register_optionflag('REMOTE_DATA') def pytest_configure(config): doctest_plugin = config.pluginmanager.getplugin('doctest') if (doctest_plugin is None or config.option.doctestmodules or not (config.getini('doctest_plus') or config.option.doctest_plus)): return # These are the default doctest options we use for everything. # There shouldn't be any need to manually put them in doctests # themselves. opts = (doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | FIX) class DocTestModulePlus(doctest_plugin.DoctestModule): # pytest 2.4.0 defines "collect". Prior to that, it defined # "runtest". The "collect" approach is better, because we can # skip modules altogether that have no doctests. However, we # need to continue to override "runtest" so that the built-in # behavior (which doesn't do whitespace normalization or # handling __doctest_skip__) doesn't happen. def collect(self): # When running directly from pytest we need to make sure that we # don't accidentally import setup.py! if self.fspath.basename == "setup.py": return elif self.fspath.basename == "conftest.py": try: module = self.config._conftest.importconftest(self.fspath) except AttributeError: # pytest >= 2.8.0 module = self.config.pluginmanager._importconftest(self.fspath) else: try: module = self.fspath.pyimport() # Just ignore searching modules that can't be imported when # collecting doctests except ImportError: return # uses internal doctest module parsing mechanism finder = DocTestFinderPlus() runner = doctest.DebugRunner( verbose=False, optionflags=opts, checker=OutputChecker()) for test in finder.find(module): if test.examples: # skip empty doctests if config.getoption('remote_data', 'none') != 'any': for example in test.examples: if example.options.get(REMOTE_DATA): example.options[doctest.SKIP] = True yield doctest_plugin.DoctestItem( test.name, self, runner, test) class DocTestTextfilePlus(doctest_plugin.DoctestItem, pytest.Module): # Some pytest plugins such as hypothesis try and access the 'obj' # attribute, and by default this returns an error for this class # so we override it here to avoid any issues. def obj(self): pass def runtest(self): # satisfy `FixtureRequest` constructor... self.funcargs = {} fixture_request = doctest_plugin._setup_fixtures(self) failed, tot = doctest.testfile( str(self.fspath), module_relative=False, optionflags=opts, parser=DocTestParserPlus(), extraglobs=dict(getfixture=fixture_request.getfuncargvalue), raise_on_error=True, verbose=False, encoding='utf-8') def reportinfo(self): """ Overwrite pytest's ``DoctestItem`` because ``DocTestTextfilePlus`` does not have a ``dtest`` attribute which is used by pytest>=3.2.0 to return the location of the tests. For details see `pytest-dev/pytest#2651 `_. """ return self.fspath, None, "[doctest] %s" % self.name class DocTestParserPlus(doctest.DocTestParser): """ An extension to the builtin DocTestParser that handles the special directives for skipping tests. The directives are: - ``.. doctest-skip::``: Skip the next doctest chunk. - ``.. doctest-requires:: module1, module2``: Skip the next doctest chunk if the given modules/packages are not installed. - ``.. doctest-skip-all``: Skip all subsequent doctests. """ def parse(self, s, name=None): result = doctest.DocTestParser.parse(self, s, name=name) # result is a sequence of alternating text chunks and # doctest.Example objects. We need to look in the text # chunks for the special directives that help us determine # whether the following examples should be skipped. required = [] skip_next = False skip_all = False for entry in result: if isinstance(entry, six.string_types) and entry: required = [] skip_next = False lines = entry.strip().splitlines() if '.. doctest-skip-all' in (x.strip() for x in lines): skip_all = True continue if not len(lines): continue last_line = lines[-1] match = re.match( r'\.\.\s+doctest-skip\s*::(\s+.*)?', last_line) if match: marker = match.group(1) if (marker is None or (marker.strip() == 'win32' and sys.platform == 'win32')): skip_next = True continue match = re.match( r'\.\.\s+doctest-requires\s*::\s+(.*)', last_line) if match: required = re.split(r'\s*,?\s*', match.group(1)) elif isinstance(entry, doctest.Example): if (skip_all or skip_next or not DocTestFinderPlus.check_required_modules(required)): entry.options[doctest.SKIP] = True if (config.getoption('remote_data', 'none') != 'any' and entry.options.get(REMOTE_DATA)): entry.options[doctest.SKIP] = True return result config.pluginmanager.register( DoctestPlus(DocTestModulePlus, DocTestTextfilePlus, config.getini('doctest_rst') or config.option.doctest_rst), 'doctestplus') # Remove the doctest_plugin, or we'll end up testing the .rst files twice. config.pluginmanager.unregister(doctest_plugin) class DoctestPlus(object): def __init__(self, doctest_module_item_cls, doctest_textfile_item_cls, run_rst_doctests): """ doctest_module_item_cls should be a class inheriting `pytest.doctest.DoctestItem` and `pytest.File`. This class handles running of a single doctest found in a Python module. This is passed in as an argument because the actual class to be used may not be available at import time, depending on whether or not the doctest plugin for py.test is available. """ self._doctest_module_item_cls = doctest_module_item_cls self._doctest_textfile_item_cls = doctest_textfile_item_cls self._run_rst_doctests = run_rst_doctests # Directories to ignore when adding doctests self._ignore_paths = [] def pytest_ignore_collect(self, path, config): """Skip paths that match any of the doctest_norecursedirs patterns.""" for pattern in config.getini("doctest_norecursedirs"): if path.check(fnmatch=pattern): # Apparently pytest_ignore_collect causes files not to be # collected by any test runner; for DoctestPlus we only want to # avoid creating doctest nodes for them self._ignore_paths.append(path) break return False def pytest_collect_file(self, path, parent): """Implements an enhanced version of the doctest module from py.test (specifically, as enabled by the --doctest-modules option) which supports skipping all doctests in a specific docstring by way of a special ``__doctest_skip__`` module-level variable. It can also skip tests that have special requirements by way of ``__doctest_requires__``. ``__doctest_skip__`` should be a list of functions, classes, or class methods whose docstrings should be ignored when collecting doctests. This also supports wildcard patterns. For example, to run doctests in a class's docstring, but skip all doctests in its modules use, at the module level:: __doctest_skip__ = ['ClassName.*'] You may also use the string ``'.'`` in ``__doctest_skip__`` to refer to the module itself, in case its module-level docstring contains doctests. ``__doctest_requires__`` should be a dictionary mapping wildcard patterns (in the same format as ``__doctest_skip__``) to a list of one or more modules that should be *importable* in order for the tests to run. For example, if some tests require the scipy module to work they will be skipped unless ``import scipy`` is possible. It is also possible to use a tuple of wildcard patterns as a key in this dict:: __doctest_requires__ = {('func1', 'func2'): ['scipy']} """ for ignore_path in self._ignore_paths: if ignore_path.common(path) == ignore_path: return None if path.ext == '.py': if path.basename == 'conf.py': return None # Don't override the built-in doctest plugin return self._doctest_module_item_cls(path, parent) elif self._run_rst_doctests and path.ext == '.rst': # Ignore generated .rst files parts = str(path).split(os.path.sep) # Don't test files that start with a _ if path.basename.startswith('_'): return None # Don't test files in directories that start with a '_' if those # directories are inside docs. Note that we *should* allow for # example /tmp/_q/docs/file.rst but not /tmp/docs/_build/file.rst # If we don't find 'docs' in the path, we should just skip this # check to be safe. We also want to skip any api sub-directory # of docs. if 'docs' in parts: # We index from the end on the off chance that the temporary # directory includes 'docs' in the path, e.g. # /tmp/docs/371j/docs/index.rst You laugh, but who knows! :) # Also, it turns out lists don't have an rindex method. Huh??!! docs_index = len(parts) - 1 - parts[::-1].index('docs') if any(x.startswith('_') or x == 'api' for x in parts[docs_index:]): return None # TODO: Get better names on these items when they are # displayed in py.test output return self._doctest_textfile_item_cls(path, parent) class DocTestFinderPlus(doctest.DocTestFinder): """Extension to the default `doctest.DoctestFinder` that supports ``__doctest_skip__`` magic. See `pytest_collect_file` for more details. """ # Caches the results of import attempts _import_cache = {} @classmethod def check_required_modules(cls, mods): for mod in mods: if mod in cls._import_cache: if not cls._import_cache[mod]: return False try: imp.find_module(mod) except ImportError: cls._import_cache[mod] = False return False else: cls._import_cache[mod] = True return True def find(self, obj, name=None, module=None, globs=None, extraglobs=None): tests = doctest.DocTestFinder.find(self, obj, name, module, globs, extraglobs) if (hasattr(obj, '__doctest_skip__') or hasattr(obj, '__doctest_requires__')): if name is None and hasattr(obj, '__name__'): name = obj.__name__ else: raise ValueError("DocTestFinder.find: name must be given " "when obj.__name__ doesn't exist: {!r}".format( (type(obj),))) def test_filter(test): for pat in getattr(obj, '__doctest_skip__', []): if pat == '*': return False elif pat == '.' and test.name == name: return False elif fnmatch.fnmatch(test.name, '.'.join((name, pat))): return False reqs = getattr(obj, '__doctest_requires__', {}) for pats, mods in six.iteritems(reqs): if not isinstance(pats, tuple): pats = (pats,) for pat in pats: if not fnmatch.fnmatch(test.name, '.'.join((name, pat))): continue if not self.check_required_modules(mods): return False return True tests = list(filter(test_filter, tests)) return tests pytest-doctestplus-0.1.2/pytest_doctestplus/__init__.py0000644000175000017500000000022613200423543023025 0ustar dandan00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst """ This package contains pytest plugins that are used by the astropy test suite. """ pytest-doctestplus-0.1.2/setup.py0000755000175000017500000000346213212331247016457 0ustar dandan00000000000000#!/usr/bin/env python # Licensed under a 3-clause BSD style license - see LICENSE.rst # -*- encoding: utf-8 -*- import io import re from glob import glob from os.path import basename from os.path import dirname from os.path import join from os.path import splitext from setuptools import setup, find_packages def readme(): with open('README.rst') as ff: return ff.read() setup( name='pytest-doctestplus', version='0.1.2', license='BSD', description='Pytest plugin with advanced doctest features.', long_description=readme(), author='The Astropy Developers', author_email='astropy.team@gmail.com', url='https://astropy.org', packages=find_packages(), include_package_data=True, zip_safe=False, classifiers=[ # complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers 'Development Status :: 3 - Alpha', 'Framework :: Pytest', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: Implementation :: CPython', 'Topic :: Software Development :: Testing', 'Topic :: Utilities', ], keywords=[ 'doctest', 'rst', 'pytest', 'py.test' ], install_requires=[ 'six', 'pytest>=2.8.0', 'numpy>=1.10' ], python_requires='>=2.7', entry_points={ 'pytest11': [ 'pytest_doctestplus = pytest_doctestplus.plugin', ], }, ) pytest-doctestplus-0.1.2/PKG-INFO0000644000175000017500000002557413212331336016046 0ustar dandan00000000000000Metadata-Version: 1.2 Name: pytest-doctestplus Version: 0.1.2 Summary: Pytest plugin with advanced doctest features. Home-page: https://astropy.org Author: The Astropy Developers Author-email: astropy.team@gmail.com License: BSD Description-Content-Type: UNKNOWN Description: ================== pytest-doctestplus ================== This package contains a plugin for the `pytest`_ framework that provides advanced doctest support and enables the testing of `reStructuredText`_ (".rst") files. It was originally part of the `astropy`_ core package, but has been moved to a separate package in order to be of more general use. .. _pytest: https://pytest.org/en/latest/ .. _astropy: https://astropy.org/en/latest/ .. _reStructuredText: https://en.wikipedia.org/wiki/ReStructuredText Motivation ---------- This plugin provides advanced features for testing example Python code that is included in Python docstrings and in standalone documentation files. Good documentation for developers contains example code. This is true of both standalone documentation and of documentation that is integrated with the code itself. Python provides a mechanism for testing code snippets that are provided in Python docstrings. The unit test framework pytest provides a mechanism for running doctests against both docstrings in source code and in standalone documentation files. This plugin augments the functionality provided by Python and pytest by providing the following features: * approximate floating point comparison for doctests that produce floating point results (see `Floating Point Comparison`_) * skipping particular classes, methods, and functions when running doctests (see `Skipping Tests`_) * handling doctests that use remote data in conjunction with the `pytest-remotedata`_ plugin (see `Remote Data`_) * optional inclusion of ``*.rst`` files for doctests (see `Setup and Configuration`_) .. _pytest-remotedata: https://github.com/astropy/pytest-remotedata Installation ------------ The ``pytest-doctestplus`` plugin can be installed using ``pip``:: $ pip install pytest-doctestplus It is also possible to install the latest development version from the source repository:: $ git clone https://github.com/astropy/pytest-doctestplus $ cd pytest-doctestplus $ python ./setup.py install In either case, the plugin will automatically be registered for use with ``pytest``. Usage ----- .. _setup: Setup and Configuration ~~~~~~~~~~~~~~~~~~~~~~~ This plugin provides two command line options: ``--doctest-plus`` for enabling the advanced features mentioned above, and ``--doctest-rst`` for including ``*.rst`` files in doctest collection. This plugin can also be enabled by default by adding ``doctest_plus = enabled`` to the ``[tool:pytest]`` section of the package's ``setup.cfg`` file. The plugin is applied to all directories and files that ``pytest`` collects. This means that configuring ``testpaths`` and ``norecursedirs`` in ``setup.cfg`` also affects the files that will be discovered by ``pytest-doctestplus``. In addition, this plugin provides a ``doctest_norecursedirs`` configuration variable that indicates directories that should be ignored by ``pytest-doctestplus`` but do not need to be ignored by other ``pytest`` features. Doctest Directives ~~~~~~~~~~~~~~~~~~ The ``pytest-doctestplus`` plugin defines `doctest directives`_ that are used to control the behavior of particular features. For general information on directives and how they are used, consult the `documentation`_. The specifics 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 Floating Point Comparison ~~~~~~~~~~~~~~~~~~~~~~~~~ Some doctests may produce output that contains string representations of floating point values. Floating point representations are often not exact and contain roundoffs in their least significant digits. Depending on the platform the tests are being run on (different Python versions, different OS, etc.) the exact number of digits shown can differ. Because doctests work by comparing strings this can cause such tests to fail. To address this issue, the ``pytest-doctestplus`` plugin provides support for a ``FLOAT_CMP`` flag that can be used with doctests. For example: .. code-block:: python >>> 1.0 / 3.0 # doctest: +FLOAT_CMP 0.333333333333333311 When this flag is used, the expected and actual outputs are both parsed to find any floating point values in the strings. Those are then converted to actual Python `float` objects and compared numerically. This means that small differences in representation of roundoff digits will be ignored by the doctest. The values are otherwise compared exactly, so more significant (albeit possibly small) differences will still be caught by these tests. Skipping Tests ~~~~~~~~~~~~~~ Doctest provides the ``+SKIP`` directive for skipping statements that should not be executed when testing documentation. However, it is often useful to be able to skip docstrings associated with particular functions, methods, classes, or even entire files. Skip Unconditionally ^^^^^^^^^^^^^^^^^^^^ The ``pytest-doctestplus`` plugin provides a way to indicate that certain docstrings should be skipped altogether. This is configured by defining the variable ``__doctest_skip__`` in each module where tests should be skipped. The value of ``__doctest_skip__`` should be a list of wildcard patterns for all functions/classes whose doctests should be skipped. For example:: __doctest_skip__ = ['myfunction', 'MyClass', 'MyClass.*'] skips the doctests in a function called ``myfunction``, the doctest for a class called ``MyClass``, and all *methods* of ``MyClass``. Module docstrings may contain doctests as well. To skip the module-level doctests:: __doctest_skip__ = ['.', 'myfunction', 'MyClass'] To skip all doctests in a module:: __doctest_skip__ = ['*'] Doctest Dependencies ^^^^^^^^^^^^^^^^^^^^ It is also possible to skip certain doctests depending on whether particular dependencies are available. This is configured by defining the variable ``__doctest_requires__`` at the module level. The value of this variable is a dictionary that indicates the modules that are required to run the doctests associated with particular functions, classes, and methods. The keys in the dictionary are wildcard patterns like those described above, or tuples of wildcard patterns, indicating which docstrings should be skipped. The values in the dictionary are lists of module names that are required in order for the given doctests to be executed. Consider the following example:: __doctest_requires__ = {('func1', 'func2'): ['scipy']} Having this module-level variable will require ``scipy`` to be importable in order to run the doctests for functions ``func1`` and ``func2`` in that module. Remote Data ~~~~~~~~~~~ The ``pytest-doctestplus`` plugin can be used in conjunction with the `pytest-remotedata`_ plugin in order to control doctest code that requires access to data from the internet. In order to make use of these features, the ``pytest-remotedata`` plugin must be installed, and remote data access must be enabled using the ``--remote-data`` command line option to ``pytest``. See the `pytest-remotedata plugin documentation`__ for more details. The following example illustrates how a doctest that uses remote data should be marked:: .. code-block:: python >>> from urlib.request import urlopen >>> url = urlopen('http://astropy.org') # doctest: +REMOTE_DATA The ``+REMOTE_DATA`` directive indicates that the marked statement should only be executed if the ``--remote-data`` option is given. By default, all statements marked with ``--remote-data`` will be skipped. .. _pytest-remotedata: https://github.com/astropy/pytest-remotedata __ pytest-remotedata_ Development Status ------------------ .. image:: https://travis-ci.org/astropy/pytest-doctestplus.svg :target: https://travis-ci.org/astropy/pytest-doctestplus :alt: Travis CI Status .. image:: https://ci.appveyor.com/api/projects/status/vwbkv8vulemhak2p?svg=true :target: https://ci.appveyor.com/project/Astropy/pytest-remotedata/branch/master :alt: Appveyor Status Questions, bug reports, and feature requests can be submitted on `github`_. .. _github: https://github.com/astropy/pytest-doctestplus License ------- This plugin is licensed under a 3-clause BSD style license - see the ``LICENSE.rst`` file. Keywords: doctest,rst,pytest,py.test Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Framework :: Pytest Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Topic :: Software Development :: Testing Classifier: Topic :: Utilities Requires-Python: >=2.7 pytest-doctestplus-0.1.2/pytest_doctestplus.egg-info/0000755000175000017500000000000013212331336022407 5ustar dandan00000000000000pytest-doctestplus-0.1.2/pytest_doctestplus.egg-info/not-zip-safe0000644000175000017500000000000113212331336024635 0ustar dandan00000000000000 pytest-doctestplus-0.1.2/pytest_doctestplus.egg-info/SOURCES.txt0000644000175000017500000000106113212331336024271 0ustar dandan00000000000000CHANGES.rst LICENSE.rst MANIFEST.in README.rst setup.cfg setup.py pytest_doctestplus/__init__.py pytest_doctestplus/output_checker.py pytest_doctestplus/plugin.py pytest_doctestplus.egg-info/PKG-INFO pytest_doctestplus.egg-info/SOURCES.txt pytest_doctestplus.egg-info/dependency_links.txt pytest_doctestplus.egg-info/entry_points.txt pytest_doctestplus.egg-info/not-zip-safe pytest_doctestplus.egg-info/requires.txt pytest_doctestplus.egg-info/top_level.txt tests/docs/skip_all.rst tests/docs/skip_some.rst tests/python/doctests.py tests/python/skip_doctests.pypytest-doctestplus-0.1.2/pytest_doctestplus.egg-info/dependency_links.txt0000644000175000017500000000000113212331336026455 0ustar dandan00000000000000 pytest-doctestplus-0.1.2/pytest_doctestplus.egg-info/PKG-INFO0000644000175000017500000002557413212331336023521 0ustar dandan00000000000000Metadata-Version: 1.2 Name: pytest-doctestplus Version: 0.1.2 Summary: Pytest plugin with advanced doctest features. Home-page: https://astropy.org Author: The Astropy Developers Author-email: astropy.team@gmail.com License: BSD Description-Content-Type: UNKNOWN Description: ================== pytest-doctestplus ================== This package contains a plugin for the `pytest`_ framework that provides advanced doctest support and enables the testing of `reStructuredText`_ (".rst") files. It was originally part of the `astropy`_ core package, but has been moved to a separate package in order to be of more general use. .. _pytest: https://pytest.org/en/latest/ .. _astropy: https://astropy.org/en/latest/ .. _reStructuredText: https://en.wikipedia.org/wiki/ReStructuredText Motivation ---------- This plugin provides advanced features for testing example Python code that is included in Python docstrings and in standalone documentation files. Good documentation for developers contains example code. This is true of both standalone documentation and of documentation that is integrated with the code itself. Python provides a mechanism for testing code snippets that are provided in Python docstrings. The unit test framework pytest provides a mechanism for running doctests against both docstrings in source code and in standalone documentation files. This plugin augments the functionality provided by Python and pytest by providing the following features: * approximate floating point comparison for doctests that produce floating point results (see `Floating Point Comparison`_) * skipping particular classes, methods, and functions when running doctests (see `Skipping Tests`_) * handling doctests that use remote data in conjunction with the `pytest-remotedata`_ plugin (see `Remote Data`_) * optional inclusion of ``*.rst`` files for doctests (see `Setup and Configuration`_) .. _pytest-remotedata: https://github.com/astropy/pytest-remotedata Installation ------------ The ``pytest-doctestplus`` plugin can be installed using ``pip``:: $ pip install pytest-doctestplus It is also possible to install the latest development version from the source repository:: $ git clone https://github.com/astropy/pytest-doctestplus $ cd pytest-doctestplus $ python ./setup.py install In either case, the plugin will automatically be registered for use with ``pytest``. Usage ----- .. _setup: Setup and Configuration ~~~~~~~~~~~~~~~~~~~~~~~ This plugin provides two command line options: ``--doctest-plus`` for enabling the advanced features mentioned above, and ``--doctest-rst`` for including ``*.rst`` files in doctest collection. This plugin can also be enabled by default by adding ``doctest_plus = enabled`` to the ``[tool:pytest]`` section of the package's ``setup.cfg`` file. The plugin is applied to all directories and files that ``pytest`` collects. This means that configuring ``testpaths`` and ``norecursedirs`` in ``setup.cfg`` also affects the files that will be discovered by ``pytest-doctestplus``. In addition, this plugin provides a ``doctest_norecursedirs`` configuration variable that indicates directories that should be ignored by ``pytest-doctestplus`` but do not need to be ignored by other ``pytest`` features. Doctest Directives ~~~~~~~~~~~~~~~~~~ The ``pytest-doctestplus`` plugin defines `doctest directives`_ that are used to control the behavior of particular features. For general information on directives and how they are used, consult the `documentation`_. The specifics 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 Floating Point Comparison ~~~~~~~~~~~~~~~~~~~~~~~~~ Some doctests may produce output that contains string representations of floating point values. Floating point representations are often not exact and contain roundoffs in their least significant digits. Depending on the platform the tests are being run on (different Python versions, different OS, etc.) the exact number of digits shown can differ. Because doctests work by comparing strings this can cause such tests to fail. To address this issue, the ``pytest-doctestplus`` plugin provides support for a ``FLOAT_CMP`` flag that can be used with doctests. For example: .. code-block:: python >>> 1.0 / 3.0 # doctest: +FLOAT_CMP 0.333333333333333311 When this flag is used, the expected and actual outputs are both parsed to find any floating point values in the strings. Those are then converted to actual Python `float` objects and compared numerically. This means that small differences in representation of roundoff digits will be ignored by the doctest. The values are otherwise compared exactly, so more significant (albeit possibly small) differences will still be caught by these tests. Skipping Tests ~~~~~~~~~~~~~~ Doctest provides the ``+SKIP`` directive for skipping statements that should not be executed when testing documentation. However, it is often useful to be able to skip docstrings associated with particular functions, methods, classes, or even entire files. Skip Unconditionally ^^^^^^^^^^^^^^^^^^^^ The ``pytest-doctestplus`` plugin provides a way to indicate that certain docstrings should be skipped altogether. This is configured by defining the variable ``__doctest_skip__`` in each module where tests should be skipped. The value of ``__doctest_skip__`` should be a list of wildcard patterns for all functions/classes whose doctests should be skipped. For example:: __doctest_skip__ = ['myfunction', 'MyClass', 'MyClass.*'] skips the doctests in a function called ``myfunction``, the doctest for a class called ``MyClass``, and all *methods* of ``MyClass``. Module docstrings may contain doctests as well. To skip the module-level doctests:: __doctest_skip__ = ['.', 'myfunction', 'MyClass'] To skip all doctests in a module:: __doctest_skip__ = ['*'] Doctest Dependencies ^^^^^^^^^^^^^^^^^^^^ It is also possible to skip certain doctests depending on whether particular dependencies are available. This is configured by defining the variable ``__doctest_requires__`` at the module level. The value of this variable is a dictionary that indicates the modules that are required to run the doctests associated with particular functions, classes, and methods. The keys in the dictionary are wildcard patterns like those described above, or tuples of wildcard patterns, indicating which docstrings should be skipped. The values in the dictionary are lists of module names that are required in order for the given doctests to be executed. Consider the following example:: __doctest_requires__ = {('func1', 'func2'): ['scipy']} Having this module-level variable will require ``scipy`` to be importable in order to run the doctests for functions ``func1`` and ``func2`` in that module. Remote Data ~~~~~~~~~~~ The ``pytest-doctestplus`` plugin can be used in conjunction with the `pytest-remotedata`_ plugin in order to control doctest code that requires access to data from the internet. In order to make use of these features, the ``pytest-remotedata`` plugin must be installed, and remote data access must be enabled using the ``--remote-data`` command line option to ``pytest``. See the `pytest-remotedata plugin documentation`__ for more details. The following example illustrates how a doctest that uses remote data should be marked:: .. code-block:: python >>> from urlib.request import urlopen >>> url = urlopen('http://astropy.org') # doctest: +REMOTE_DATA The ``+REMOTE_DATA`` directive indicates that the marked statement should only be executed if the ``--remote-data`` option is given. By default, all statements marked with ``--remote-data`` will be skipped. .. _pytest-remotedata: https://github.com/astropy/pytest-remotedata __ pytest-remotedata_ Development Status ------------------ .. image:: https://travis-ci.org/astropy/pytest-doctestplus.svg :target: https://travis-ci.org/astropy/pytest-doctestplus :alt: Travis CI Status .. image:: https://ci.appveyor.com/api/projects/status/vwbkv8vulemhak2p?svg=true :target: https://ci.appveyor.com/project/Astropy/pytest-remotedata/branch/master :alt: Appveyor Status Questions, bug reports, and feature requests can be submitted on `github`_. .. _github: https://github.com/astropy/pytest-doctestplus License ------- This plugin is licensed under a 3-clause BSD style license - see the ``LICENSE.rst`` file. Keywords: doctest,rst,pytest,py.test Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Framework :: Pytest Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Topic :: Software Development :: Testing Classifier: Topic :: Utilities Requires-Python: >=2.7 pytest-doctestplus-0.1.2/pytest_doctestplus.egg-info/entry_points.txt0000644000175000017500000000007313212331336025705 0ustar dandan00000000000000[pytest11] pytest_doctestplus = pytest_doctestplus.plugin pytest-doctestplus-0.1.2/pytest_doctestplus.egg-info/top_level.txt0000644000175000017500000000002313212331336025134 0ustar dandan00000000000000pytest_doctestplus pytest-doctestplus-0.1.2/pytest_doctestplus.egg-info/requires.txt0000644000175000017500000000003613212331336025006 0ustar dandan00000000000000six pytest>=2.8.0 numpy>=1.10 pytest-doctestplus-0.1.2/CHANGES.rst0000644000175000017500000000044613212331247016543 0ustar dandan000000000000000.1.2 (2017-12-07) ================== - Update README. Use README for long description on PyPi. [#12] 0.1.1 (2017-10-18) ================== - Port fix from astropy core that addresses changes to numpy formatting of float scalars. [#8] 0.1 (2017-10-10) ================ - Alpha release. pytest-doctestplus-0.1.2/README.rst0000644000175000017500000002025613212331220016420 0ustar dandan00000000000000================== pytest-doctestplus ================== This package contains a plugin for the `pytest`_ framework that provides advanced doctest support and enables the testing of `reStructuredText`_ (".rst") files. It was originally part of the `astropy`_ core package, but has been moved to a separate package in order to be of more general use. .. _pytest: https://pytest.org/en/latest/ .. _astropy: https://astropy.org/en/latest/ .. _reStructuredText: https://en.wikipedia.org/wiki/ReStructuredText Motivation ---------- This plugin provides advanced features for testing example Python code that is included in Python docstrings and in standalone documentation files. Good documentation for developers contains example code. This is true of both standalone documentation and of documentation that is integrated with the code itself. Python provides a mechanism for testing code snippets that are provided in Python docstrings. The unit test framework pytest provides a mechanism for running doctests against both docstrings in source code and in standalone documentation files. This plugin augments the functionality provided by Python and pytest by providing the following features: * approximate floating point comparison for doctests that produce floating point results (see `Floating Point Comparison`_) * skipping particular classes, methods, and functions when running doctests (see `Skipping Tests`_) * handling doctests that use remote data in conjunction with the `pytest-remotedata`_ plugin (see `Remote Data`_) * optional inclusion of ``*.rst`` files for doctests (see `Setup and Configuration`_) .. _pytest-remotedata: https://github.com/astropy/pytest-remotedata Installation ------------ The ``pytest-doctestplus`` plugin can be installed using ``pip``:: $ pip install pytest-doctestplus It is also possible to install the latest development version from the source repository:: $ git clone https://github.com/astropy/pytest-doctestplus $ cd pytest-doctestplus $ python ./setup.py install In either case, the plugin will automatically be registered for use with ``pytest``. Usage ----- .. _setup: Setup and Configuration ~~~~~~~~~~~~~~~~~~~~~~~ This plugin provides two command line options: ``--doctest-plus`` for enabling the advanced features mentioned above, and ``--doctest-rst`` for including ``*.rst`` files in doctest collection. This plugin can also be enabled by default by adding ``doctest_plus = enabled`` to the ``[tool:pytest]`` section of the package's ``setup.cfg`` file. The plugin is applied to all directories and files that ``pytest`` collects. This means that configuring ``testpaths`` and ``norecursedirs`` in ``setup.cfg`` also affects the files that will be discovered by ``pytest-doctestplus``. In addition, this plugin provides a ``doctest_norecursedirs`` configuration variable that indicates directories that should be ignored by ``pytest-doctestplus`` but do not need to be ignored by other ``pytest`` features. Doctest Directives ~~~~~~~~~~~~~~~~~~ The ``pytest-doctestplus`` plugin defines `doctest directives`_ that are used to control the behavior of particular features. For general information on directives and how they are used, consult the `documentation`_. The specifics 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 Floating Point Comparison ~~~~~~~~~~~~~~~~~~~~~~~~~ Some doctests may produce output that contains string representations of floating point values. Floating point representations are often not exact and contain roundoffs in their least significant digits. Depending on the platform the tests are being run on (different Python versions, different OS, etc.) the exact number of digits shown can differ. Because doctests work by comparing strings this can cause such tests to fail. To address this issue, the ``pytest-doctestplus`` plugin provides support for a ``FLOAT_CMP`` flag that can be used with doctests. For example: .. code-block:: python >>> 1.0 / 3.0 # doctest: +FLOAT_CMP 0.333333333333333311 When this flag is used, the expected and actual outputs are both parsed to find any floating point values in the strings. Those are then converted to actual Python `float` objects and compared numerically. This means that small differences in representation of roundoff digits will be ignored by the doctest. The values are otherwise compared exactly, so more significant (albeit possibly small) differences will still be caught by these tests. Skipping Tests ~~~~~~~~~~~~~~ Doctest provides the ``+SKIP`` directive for skipping statements that should not be executed when testing documentation. However, it is often useful to be able to skip docstrings associated with particular functions, methods, classes, or even entire files. Skip Unconditionally ^^^^^^^^^^^^^^^^^^^^ The ``pytest-doctestplus`` plugin provides a way to indicate that certain docstrings should be skipped altogether. This is configured by defining the variable ``__doctest_skip__`` in each module where tests should be skipped. The value of ``__doctest_skip__`` should be a list of wildcard patterns for all functions/classes whose doctests should be skipped. For example:: __doctest_skip__ = ['myfunction', 'MyClass', 'MyClass.*'] skips the doctests in a function called ``myfunction``, the doctest for a class called ``MyClass``, and all *methods* of ``MyClass``. Module docstrings may contain doctests as well. To skip the module-level doctests:: __doctest_skip__ = ['.', 'myfunction', 'MyClass'] To skip all doctests in a module:: __doctest_skip__ = ['*'] Doctest Dependencies ^^^^^^^^^^^^^^^^^^^^ It is also possible to skip certain doctests depending on whether particular dependencies are available. This is configured by defining the variable ``__doctest_requires__`` at the module level. The value of this variable is a dictionary that indicates the modules that are required to run the doctests associated with particular functions, classes, and methods. The keys in the dictionary are wildcard patterns like those described above, or tuples of wildcard patterns, indicating which docstrings should be skipped. The values in the dictionary are lists of module names that are required in order for the given doctests to be executed. Consider the following example:: __doctest_requires__ = {('func1', 'func2'): ['scipy']} Having this module-level variable will require ``scipy`` to be importable in order to run the doctests for functions ``func1`` and ``func2`` in that module. Remote Data ~~~~~~~~~~~ The ``pytest-doctestplus`` plugin can be used in conjunction with the `pytest-remotedata`_ plugin in order to control doctest code that requires access to data from the internet. In order to make use of these features, the ``pytest-remotedata`` plugin must be installed, and remote data access must be enabled using the ``--remote-data`` command line option to ``pytest``. See the `pytest-remotedata plugin documentation`__ for more details. The following example illustrates how a doctest that uses remote data should be marked:: .. code-block:: python >>> from urlib.request import urlopen >>> url = urlopen('http://astropy.org') # doctest: +REMOTE_DATA The ``+REMOTE_DATA`` directive indicates that the marked statement should only be executed if the ``--remote-data`` option is given. By default, all statements marked with ``--remote-data`` will be skipped. .. _pytest-remotedata: https://github.com/astropy/pytest-remotedata __ pytest-remotedata_ Development Status ------------------ .. image:: https://travis-ci.org/astropy/pytest-doctestplus.svg :target: https://travis-ci.org/astropy/pytest-doctestplus :alt: Travis CI Status .. image:: https://ci.appveyor.com/api/projects/status/vwbkv8vulemhak2p?svg=true :target: https://ci.appveyor.com/project/Astropy/pytest-remotedata/branch/master :alt: Appveyor Status Questions, bug reports, and feature requests can be submitted on `github`_. .. _github: https://github.com/astropy/pytest-doctestplus License ------- This plugin is licensed under a 3-clause BSD style license - see the ``LICENSE.rst`` file. pytest-doctestplus-0.1.2/MANIFEST.in0000644000175000017500000000023413200423543016470 0ustar dandan00000000000000include LICENSE.rst include README.rst include CHANGES.rst include setup.cfg include tests/python/*.py include tests/docs/*.rst global-exclude *.pyc *.o pytest-doctestplus-0.1.2/tests/0000755000175000017500000000000013212331336016076 5ustar dandan00000000000000pytest-doctestplus-0.1.2/tests/docs/0000755000175000017500000000000013212331336017026 5ustar dandan00000000000000pytest-doctestplus-0.1.2/tests/docs/skip_all.rst0000644000175000017500000000120313200423543021351 0ustar dandan00000000000000.. doctest-skip-all 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 pytest-doctestplus-0.1.2/tests/docs/skip_some.rst0000644000175000017500000000222713200423543021553 0ustar dandan00000000000000Some Good Test Cases ******************** Some of the example code blocks in this file are perfectly valid and will pass 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. Here's One That Works ===================== This code block should work just fine:: >>> 1 + 1 2 This one should work just fine as well:: >>> x = 5 >>> x 5 Here's One That Doesn't ======================= This code won't run. So let's make sure that it gets skipped: .. doctest-skip:: >>> y + z 42 This one doesn't work either: .. doctest-skip:: >>> print(blue) 'blue' Good Imports ============ There should be nothing wrong with this code, so we'll let it run:: >>> import os >>> os.path.curdir '.' Make sure the `doctest-requires` directive works for modules that are available: .. doctest-requires:: sys >>> import sys Bad Imports =========== I don't think this module exists, so we should make sure that this code doesn't run: .. doctest-requires:: foobar >>> import foobar >>> foobar.baz(42) 1 pytest-doctestplus-0.1.2/tests/python/0000755000175000017500000000000013212331336017417 5ustar dandan00000000000000pytest-doctestplus-0.1.2/tests/python/skip_doctests.py0000644000175000017500000000113613200423543022647 0ustar dandan00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst # Skip all tests in this file since they'll all fail __doctest_skip__ = ['*'] def bad_doctest(): """ This test will fail if __doctest_skip__ is not working properly. >>> x + y 5 """ def another_bad_doctest(): """ This test will fail if __doctest_skip__ is not working properly. >>> import foobar >>> foobar.baz() 5 """ def yet_another_bad_doctest(): """ This test will fail if __doctest_skip__ is not working properly. >>> NOT VALID PYTHON, RIGHT >>> + 7 42 """ pytest-doctestplus-0.1.2/tests/python/doctests.py0000644000175000017500000000350413200423543021622 0ustar dandan00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst __doctest_skip__ = [ 'skip_this_test', 'ClassWithSomeBadDocTests.this_test_fails', 'ClassWithAllBadDocTests.*', ] __doctest_requires__ = { 'depends_on_foobar': ['foobar'], 'depends_on_two_modules': ['os', 'foobar'], } def this_test_works(): """ This test should be executed by --doctest-plus and should pass. >>> 1 + 1 2 """ def skip_this_test(): """ This test will cause a failure if __doctest_skip__ is not working properly. >>> x + y 2 """ def depends_on_real_module(): """ This test should be executed by --doctest-plus and should pass. >>> import os >>> os.path.curdir '.' """ def depends_on_foobar(): """ This test will cause a failure if __doctest_requires__ is not working. >>> import foobar >>> foobar.foo.bar('baz') 42 """ def depends_on_two_modules(): """ This test will cause a failure if __doctest_requires__ is not working. >>> import os >>> import foobar >>> foobar.foo.bar(os.path.curdir) 'The meaning of life' """ class ClassWithSomeBadDocTests(object): def this_test_works(): """ This test should be executed by --doctest-plus and should pass. >>> 1 + 1 2 """ def this_test_fails(): """ This test will cause a failure if __doctest_skip__ is not working. >>> x + y 5 """ class ClassWithAllBadDocTests(object): def this_test_fails(): """ This test will cause a failure if __doctest_skip__ is not working. >>> x + y 5 """ def this_test_also_fails(): """ This test will cause a failure if __doctest_skip__ is not working. >>> print(blue) 'blue' """