diff -Nru pytest-doctestplus-0.7.0/CHANGES.rst pytest-doctestplus-0.9.0/CHANGES.rst --- pytest-doctestplus-0.7.0/CHANGES.rst 2020-05-20 14:57:53.000000000 +0000 +++ pytest-doctestplus-0.9.0/CHANGES.rst 2021-01-15 01:19:47.000000000 +0000 @@ -1,3 +1,19 @@ +0.9.0 (2021-01-14) +================== + +- Declare ``setuptools`` runtime dependency [#93] + +- Add ``SHOW_WARNINGS`` flag to show warnings. [#136] + +- Add the doctestplus sphinx extension. [#113] + +- Compatibility with pytest>=6.3 [#140, #141] + +0.8.0 (2020-07-31) +================== + +- Compatibility with ``pytest`` 6.0.0. [#120] + 0.7.0 (2020-05-20) ================== diff -Nru pytest-doctestplus-0.7.0/debian/changelog pytest-doctestplus-0.9.0/debian/changelog --- pytest-doctestplus-0.7.0/debian/changelog 2020-12-11 09:35:14.000000000 +0000 +++ pytest-doctestplus-0.9.0/debian/changelog 2021-01-17 14:35:03.000000000 +0000 @@ -1,3 +1,11 @@ +pytest-doctestplus (0.9.0-1) unstable; urgency=medium + + * New upstream version 0.9.0 + * Push Standards-Version to 4.5.1. No changes needed + * Adjust build dependencies + + -- Ole Streicher Sun, 17 Jan 2021 15:35:03 +0100 + pytest-doctestplus (0.7.0-2) unstable; urgency=medium [ Ondřej Nový ] diff -Nru pytest-doctestplus-0.7.0/debian/control pytest-doctestplus-0.9.0/debian/control --- pytest-doctestplus-0.7.0/debian/control 2020-12-11 09:35:00.000000000 +0000 +++ pytest-doctestplus-0.9.0/debian/control 2021-01-17 14:34:22.000000000 +0000 @@ -9,8 +9,8 @@ python3-pip, python3-pytest (>= 4~), python3-setuptools, - python3-six -Standards-Version: 4.5.0 + python3-setuptools-scm +Standards-Version: 4.5.1 Homepage: https://github.com/astropy/pytest-doctestplus Vcs-Browser: https://salsa.debian.org/python-team/packages/pytest-doctestplus Vcs-Git: https://salsa.debian.org/python-team/packages/pytest-doctestplus.git diff -Nru pytest-doctestplus-0.7.0/debian/patches/Compatibility-with-pytest-6.0.0.patch pytest-doctestplus-0.9.0/debian/patches/Compatibility-with-pytest-6.0.0.patch --- pytest-doctestplus-0.7.0/debian/patches/Compatibility-with-pytest-6.0.0.patch 2020-12-11 09:34:36.000000000 +0000 +++ pytest-doctestplus-0.9.0/debian/patches/Compatibility-with-pytest-6.0.0.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,50 +0,0 @@ -From: Pey Lian Lim <2090236+pllim@users.noreply.github.com> -Date: Tue, 28 Jul 2020 16:40:37 -0400 -Subject: Compatibility with pytest 6.0.0 - -This enables forward compatibility with pytest 6.0.0. - -Bug: https://github.com/astropy/pytest-doctestplus/issues/118 -Origin: https://github.com/astropy/pytest-doctestplus/pull/120/commits/1a661006d8d01986830a7baf3812cfce63ec2705 - -Closes: #977110 ---- - pytest_doctestplus/plugin.py | 11 ++++++++++- - 1 file changed, 10 insertions(+), 1 deletion(-) - -diff --git a/pytest_doctestplus/plugin.py b/pytest_doctestplus/plugin.py -index e6556a2..10109b0 100644 ---- a/pytest_doctestplus/plugin.py -+++ b/pytest_doctestplus/plugin.py -@@ -10,6 +10,8 @@ import re - import sys - import warnings - -+from packaging.version import Version -+ - import pytest - - from pytest_doctestplus.utils import ModuleChecker -@@ -21,6 +23,8 @@ except ImportError: # PY2 - def indent(text, prefix): - return '\n'.join([prefix + line for line in text.splitlines()]) - -+PYTEST_GT_5 = Version(pytest.__version__) > Version('5.9.9') -+ - comment_characters = { - '.txt': '#', - '.tex': '%', -@@ -169,7 +173,12 @@ def pytest_configure(config): - if self.fspath.basename == "setup.py": - return - elif self.fspath.basename == "conftest.py": -- module = self.config.pluginmanager._importconftest(self.fspath) -+ if PYTEST_GT_5: -+ module = self.config.pluginmanager._importconftest( -+ self.fspath, self.config.getoption("importmode")) -+ else: -+ module = self.config.pluginmanager._importconftest( -+ self.fspath) - else: - try: - module = self.fspath.pyimport() diff -Nru pytest-doctestplus-0.7.0/debian/patches/series pytest-doctestplus-0.9.0/debian/patches/series --- pytest-doctestplus-0.7.0/debian/patches/series 2020-12-11 09:34:36.000000000 +0000 +++ pytest-doctestplus-0.9.0/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -Compatibility-with-pytest-6.0.0.patch diff -Nru pytest-doctestplus-0.7.0/debian/rules pytest-doctestplus-0.9.0/debian/rules --- pytest-doctestplus-0.7.0/debian/rules 2020-11-28 15:51:25.000000000 +0000 +++ pytest-doctestplus-0.9.0/debian/rules 2021-01-17 14:33:29.000000000 +0000 @@ -1,6 +1,8 @@ #!/usr/bin/make -f # -*- makefile -*- +export SETUPTOOLS_SCM_PRETEND_VERSION=${DEB_VERSION_UPSTREAM} + %: dh $@ --with python3 --buildsystem=pybuild diff -Nru pytest-doctestplus-0.7.0/debian/tests/control pytest-doctestplus-0.9.0/debian/tests/control --- pytest-doctestplus-0.7.0/debian/tests/control 2020-11-28 15:51:25.000000000 +0000 +++ pytest-doctestplus-0.9.0/debian/tests/control 2021-01-17 14:35:03.000000000 +0000 @@ -1,5 +1,5 @@ Test-Command: PY_IGNORE_IMPORTMISMATCH=1 pytest-3 --doctest-plus -Depends: @, python3-pip +Depends: @, python3-pip, python3-docutils Test-Command: PY_IGNORE_IMPORTMISMATCH=1 pytest-3 --doctest-plus --doctest-rst -Depends: @, python3-pip +Depends: @, python3-pip, python3-docutils diff -Nru pytest-doctestplus-0.7.0/.github/workflows/publish.yml pytest-doctestplus-0.9.0/.github/workflows/publish.yml --- pytest-doctestplus-0.7.0/.github/workflows/publish.yml 1970-01-01 00:00:00.000000000 +0000 +++ pytest-doctestplus-0.9.0/.github/workflows/publish.yml 2021-01-15 01:19:47.000000000 +0000 @@ -0,0 +1,43 @@ +name: Release + +on: + push: + +jobs: + build-n-publish: + name: Build and publish Python 🐍 distributions 📦 to PyPI + runs-on: ubuntu-latest + if: github.repository == 'astropy/pytest-doctestplus' + + steps: + - uses: actions/checkout@master + with: + fetch-depth: 0 + - uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Install python-build and twine + run: python -m pip install build "twine>=3.3" + + - name: Build package + run: python -m build --sdist --wheel . + + - name: List result + run: ls -l dist + + - name: Check long_description + run: python -m twine check --strict dist/* + + - name: Test package + run: | + cd .. + python -m venv testenv + testenv/bin/pip install pytest pytest-doctestplus/dist/*.whl + testenv/bin/pytest pytest-doctestplus/tests --doctest-plus --doctest-rst + + - name: Publish distribution 📦 to PyPI + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@master + with: + password: ${{ secrets.pypi_password }} diff -Nru pytest-doctestplus-0.7.0/.github/workflows/python-tests.yml pytest-doctestplus-0.9.0/.github/workflows/python-tests.yml --- pytest-doctestplus-0.7.0/.github/workflows/python-tests.yml 1970-01-01 00:00:00.000000000 +0000 +++ pytest-doctestplus-0.9.0/.github/workflows/python-tests.yml 2021-01-15 01:19:47.000000000 +0000 @@ -0,0 +1,64 @@ +name: Run unit tests + +on: + pull_request: + push: + branches: [ master ] + tags: + workflow_dispatch: + schedule: + # Run every Sunday at 03:53 UTC + - cron: 53 3 * * 0 + +jobs: + tests: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + python-version: 3.6 + toxenv: py36-test-pytest46 + - os: windows-latest + python-version: 3.6 + toxenv: py36-test-pytest50 + - os: macos-latest + python-version: 3.7 + toxenv: py37-test-pytest51 + - os: ubuntu-latest + python-version: 3.7 + toxenv: py37-test-pytest52 + - os: windows-latest + python-version: 3.8 + toxenv: py38-test-pytest53 + - os: ubuntu-latest + python-version: 3.8 + toxenv: py38-test-pytest60 + - os: ubuntu-latest + python-version: 3.9 + toxenv: py39-test-pytest61 + - os: macos-latest + python-version: 3.8 + toxenv: py38-test-pytestdev + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install Tox + run: python -m pip install tox + - name: Run Tox + run: tox -v -e ${{ matrix.toxenv }} + + # - name: Slack Notification + # uses: 8398a7/action-slack@v3 + # with: + # status: ${{ job.status }} + # env: + # SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + # if: always() # TODO: cron diff -Nru pytest-doctestplus-0.7.0/.gitignore pytest-doctestplus-0.9.0/.gitignore --- pytest-doctestplus-0.7.0/.gitignore 1970-01-01 00:00:00.000000000 +0000 +++ pytest-doctestplus-0.9.0/.gitignore 2021-01-15 01:19:47.000000000 +0000 @@ -0,0 +1,63 @@ +# Compiled files +*.py[cod] +*.a +*.o +*.so +*.pyd +__pycache__ + +# Ignore .c files by default to avoid including generated code. If you want to +# add a non-generated .c extension, use `git add -f filename.c`. +*.c + +# Other generated files +MANIFEST + +# Sphinx +_build +_generated +docs/api +docs/generated + +# Packages/installer info +*.egg +*.egg-info +dist +build +eggs +.eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg +distribute-*.tar.gz + +# Other +.cache +.tox +.*.swp +.*.swo +*~ +.project +.pydevproject +.settings +.coverage +cover +htmlcov +.pytest_cache + +# Env +.venv +venv +.env + +# Mac OSX +.DS_Store + +# PyCharm +.idea + +pytest_doctestplus/version.py +pip-wheel-metadata/ diff -Nru pytest-doctestplus-0.7.0/licenses/README.rst pytest-doctestplus-0.9.0/licenses/README.rst --- pytest-doctestplus-0.7.0/licenses/README.rst 1970-01-01 00:00:00.000000000 +0000 +++ pytest-doctestplus-0.9.0/licenses/README.rst 2021-01-15 01:19:47.000000000 +0000 @@ -0,0 +1,6 @@ +Licenses +======== + +This directory holds license and credit information for works this plugin is derived from or distributes, and/or datasets. + +The license file for this package itself is placed in the root directory of this repository. diff -Nru pytest-doctestplus-0.7.0/licenses/SYMPY_LICENSE.rst pytest-doctestplus-0.9.0/licenses/SYMPY_LICENSE.rst --- pytest-doctestplus-0.7.0/licenses/SYMPY_LICENSE.rst 1970-01-01 00:00:00.000000000 +0000 +++ pytest-doctestplus-0.9.0/licenses/SYMPY_LICENSE.rst 2021-01-15 01:19:47.000000000 +0000 @@ -0,0 +1,28 @@ +Copyright (c) 2006-2014 SymPy Development Team + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + a. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + b. 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. + c. Neither the name of SymPy 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 REGENTS 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. diff -Nru pytest-doctestplus-0.7.0/PKG-INFO pytest-doctestplus-0.9.0/PKG-INFO --- pytest-doctestplus-0.7.0/PKG-INFO 2020-05-20 14:58:54.000000000 +0000 +++ pytest-doctestplus-0.9.0/PKG-INFO 2021-01-15 01:19:55.924952300 +0000 @@ -1,8 +1,8 @@ -Metadata-Version: 1.2 +Metadata-Version: 2.1 Name: pytest-doctestplus -Version: 0.7.0 +Version: 0.9.0 Summary: Pytest plugin with advanced doctest features. -Home-page: https://astropy.org +Home-page: https://github.com/astropy/pytest-doctestplus Author: The Astropy Developers Author-email: astropy.team@gmail.com License: BSD @@ -16,7 +16,7 @@ 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/ + .. _astropy: https://astropy.org/ .. _reStructuredText: https://en.wikipedia.org/wiki/ReStructuredText @@ -57,7 +57,7 @@ $ git clone https://github.com/astropy/pytest-doctestplus $ cd pytest-doctestplus - $ python ./setup.py install + $ pip install . In either case, the plugin will automatically be registered for use with ``pytest``. @@ -155,6 +155,23 @@ >>> np.mean([]) # doctest: +IGNORE_WARNINGS np.nan + Showing warnings + ~~~~~~~~~~~~~~~~ + + If code in a doctest emits a warning and you want to make sure that warning is + shown, you can make use of the ``SHOW_WARNINGS`` flag. This is useful when + warnings are turned into errors by pytest, and also because by default warnings + are printed to stderr. This is the opposite from ``IGNORE_WARNINGS`` so + obviously the two flags should not be used together. For example: + + .. code-block:: python + + >>> import numpy as np + >>> np.mean([]) # doctest: +SHOW_WARNINGS + RuntimeWarning: Mean of empty slice. + RuntimeWarning: invalid value encountered in double_scalars + np.nan + Skipping Tests ~~~~~~~~~~~~~~ @@ -269,12 +286,23 @@ .. _pytest-remotedata: https://github.com/astropy/pytest-remotedata __ pytest-remotedata_ + Sphinx Compatibility + ~~~~~~~~~~~~~~~~~~~~ + + To use the additional directives when building your documentation with sphinx + you may want to enable the sphinx extension which registers these directives + with sphinx. Doing so ensures that sphinx correctly ignores these directives, + running the doctests with sphinx is not supported. To do this, add + ``'pytest_doctestplus.sphinx.doctestplus'`` to your ``extensions`` list in your + ``conf.py`` file. + + 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://github.com/astropy/pytest-doctestplus/workflows/Run%20unit%20tests/badge.svg + :target: https://github.com/astropy/pytest-doctestplus/actions + :alt: CI Status Questions, bug reports, and feature requests can be submitted on `github`_. @@ -294,6 +322,7 @@ Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 @@ -301,3 +330,4 @@ Classifier: Topic :: Software Development :: Testing Classifier: Topic :: Utilities Requires-Python: >=3.6 +Description-Content-Type: text/x-rst diff -Nru pytest-doctestplus-0.7.0/pyproject.toml pytest-doctestplus-0.9.0/pyproject.toml --- pytest-doctestplus-0.7.0/pyproject.toml 1970-01-01 00:00:00.000000000 +0000 +++ pytest-doctestplus-0.9.0/pyproject.toml 2021-01-15 01:19:47.000000000 +0000 @@ -0,0 +1,5 @@ +[build-system] +requires = ["setuptools>=30.3.0", + "setuptools_scm", + "wheel"] +build-backend = 'setuptools.build_meta' diff -Nru pytest-doctestplus-0.7.0/pytest_doctestplus/__init__.py pytest-doctestplus-0.9.0/pytest_doctestplus/__init__.py --- pytest-doctestplus-0.7.0/pytest_doctestplus/__init__.py 2020-05-20 14:57:20.000000000 +0000 +++ pytest-doctestplus-0.9.0/pytest_doctestplus/__init__.py 2021-01-15 01:19:47.000000000 +0000 @@ -1,6 +1,3 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst -""" -This package contains pytest plugins that are used by the astropy test suite. -""" -__version__ = '0.7.0' +from .version import version as __version__ # noqa diff -Nru pytest-doctestplus-0.7.0/pytest_doctestplus/output_checker.py pytest-doctestplus-0.9.0/pytest_doctestplus/output_checker.py --- pytest-doctestplus-0.7.0/pytest_doctestplus/output_checker.py 2020-05-20 14:56:16.000000000 +0000 +++ pytest-doctestplus-0.9.0/pytest_doctestplus/output_checker.py 2021-01-15 01:19:47.000000000 +0000 @@ -20,6 +20,7 @@ IGNORE_OUTPUT = doctest.register_optionflag('IGNORE_OUTPUT') IGNORE_OUTPUT_3 = doctest.register_optionflag('IGNORE_OUTPUT_3') IGNORE_WARNINGS = doctest.register_optionflag('IGNORE_WARNINGS') +SHOW_WARNINGS = doctest.register_optionflag('SHOW_WARNINGS') # These might appear in some doctests and are used in the default pytest # doctest plugin. This plugin doesn't actually implement these flags but this diff -Nru pytest-doctestplus-0.7.0/pytest_doctestplus/plugin.py pytest-doctestplus-0.9.0/pytest_doctestplus/plugin.py --- pytest-doctestplus-0.7.0/pytest_doctestplus/plugin.py 2020-05-20 14:56:16.000000000 +0000 +++ pytest-doctestplus-0.9.0/pytest_doctestplus/plugin.py 2021-01-15 01:19:47.000000000 +0000 @@ -9,17 +9,20 @@ import re import sys import warnings +from pathlib import Path +from textwrap import indent import pytest +from packaging.version import Version from pytest_doctestplus.utils import ModuleChecker -from .output_checker import FIX, IGNORE_WARNINGS, OutputChecker, REMOTE_DATA -try: - from textwrap import indent -except ImportError: # PY2 - def indent(text, prefix): - return '\n'.join([prefix + line for line in text.splitlines()]) +from .output_checker import (FIX, IGNORE_WARNINGS, REMOTE_DATA, SHOW_WARNINGS, + OutputChecker) + +_pytest_version = Version(pytest.__version__) +PYTEST_GT_5 = _pytest_version > Version('5.9.9') +PYTEST_GE_6_3 = _pytest_version.is_devrelease or _pytest_version >= Version('6.3') comment_characters = { '.txt': '#', @@ -28,12 +31,12 @@ } -# For the IGNORE_WARNINGS option, we create a context manager that doesn't -# require us to add any imports to the example list and contains everything -# that is needed to silence warnings. +# For the IGNORE_WARNINGS and SHOW_WARNINGS option, we create a context manager +# that doesn't require us to add any imports to the example list and contains +# everything that is needed to silence or print warnings. IGNORE_WARNINGS_CONTEXT = """ -class _doctestplus_ignore_all_warnings(object): +class _doctestplus_ignore_all_warnings: def __init__(self): import warnings @@ -50,6 +53,26 @@ """.lstrip() +SHOW_WARNINGS_CONTEXT = """ +class _doctestplus_show_all_warnings: + + def __init__(self): + import warnings + self._cw = warnings.catch_warnings(record=True) + + def __enter__(self, *args, **kwargs): + self.result = self._cw.__enter__(*args, **kwargs) + import warnings + warnings.simplefilter('always') + return self.result + + def __exit__(self, *args, **kwargs): + self._cw.__exit__(*args, **kwargs) + for warn in self.result: + print(f'{warn._category_name}: {warn.message}') +""".lstrip() + + # these pytest hooks allow us to mark tests and run the marked tests with # specific command line options. def pytest_addoption(parser): @@ -169,7 +192,15 @@ if self.fspath.basename == "setup.py": return elif self.fspath.basename == "conftest.py": - module = self.config.pluginmanager._importconftest(self.fspath) + if PYTEST_GE_6_3: + module = self.config.pluginmanager._importconftest( + Path(self.fspath), self.config.getoption("importmode")) + elif PYTEST_GT_5: + module = self.config.pluginmanager._importconftest( + self.fspath, self.config.getoption("importmode")) + else: + module = self.config.pluginmanager._importconftest( + self.fspath) else: try: module = self.fspath.pyimport() @@ -191,6 +222,7 @@ if config.getoption('remote_data', 'none') != 'any': ignore_warnings_context_needed = False + show_warnings_context_needed = False for example in test.examples: @@ -201,13 +233,24 @@ + indent(example.source, ' ')) ignore_warnings_context_needed = True + # Same for SHOW_WARNINGS + if example.options.get(SHOW_WARNINGS, False): + example.source = ("with _doctestplus_show_all_warnings():\n" + + indent(example.source, ' ')) + show_warnings_context_needed = True + if example.options.get(REMOTE_DATA): example.options[doctest.SKIP] = True # We insert the definition of the context manager to ignore # warnings at the start of the file if needed. if ignore_warnings_context_needed: - test.examples.insert(0, doctest.Example(source=IGNORE_WARNINGS_CONTEXT, want='')) + test.examples.insert(0, doctest.Example( + source=IGNORE_WARNINGS_CONTEXT, want='')) + + if show_warnings_context_needed: + test.examples.insert(0, doctest.Example( + source=SHOW_WARNINGS_CONTEXT, want='')) try: yield doctest_plugin.DoctestItem.from_parent( @@ -280,6 +323,7 @@ comment_char = comment_characters[ext] ignore_warnings_context_needed = False + show_warnings_context_needed = False for entry in result: @@ -335,6 +379,12 @@ + indent(entry.source, ' ')) ignore_warnings_context_needed = True + # Same to show warnings + if entry.options.get(SHOW_WARNINGS, False): + entry.source = ("with _doctestplus_show_all_warnings():\n" + + indent(entry.source, ' ')) + show_warnings_context_needed = True + has_required_modules = DocTestFinderPlus.check_required_modules(required) if skip_all or skip_next or not has_required_modules: entry.options[doctest.SKIP] = True @@ -347,6 +397,9 @@ if ignore_warnings_context_needed: result.insert(0, doctest.Example(source=IGNORE_WARNINGS_CONTEXT, want='')) + if show_warnings_context_needed: + result.insert(0, doctest.Example(source=SHOW_WARNINGS_CONTEXT, want='')) + return result config.pluginmanager.register( @@ -382,7 +435,11 @@ Skip paths that match any of the doctest_norecursedirs patterns or if doctest_only is True then skip all regular test files (eg test_*.py). """ - collect_ignore = config._getconftest_pathlist("collect_ignore", path=path.dirpath()) + if PYTEST_GE_6_3: + dirpath = Path(path).parent + else: + dirpath = path.dirpath() + collect_ignore = config._getconftest_pathlist("collect_ignore", path=dirpath) # The collect_ignore conftest.py variable should cause all test # runners to ignore this file and all subfiles and subdirectories diff -Nru pytest-doctestplus-0.7.0/pytest_doctestplus/sphinx/doctestplus.py pytest-doctestplus-0.9.0/pytest_doctestplus/sphinx/doctestplus.py --- pytest-doctestplus-0.7.0/pytest_doctestplus/sphinx/doctestplus.py 1970-01-01 00:00:00.000000000 +0000 +++ pytest-doctestplus-0.9.0/pytest_doctestplus/sphinx/doctestplus.py 2021-01-15 01:19:47.000000000 +0000 @@ -0,0 +1,56 @@ +# Licensed under a 3-clause BSD style license - see LICENSE.rst +""" +This is a set of three directives that allow us to insert metadata +about doctests into the .rst files so the testing framework knows +which tests to skip. + +This is quite different from the doctest extension in Sphinx itself, +which actually does something. For astropy, all of the testing is +centrally managed from py.test and Sphinx is not used for running +tests. +""" +import re +from docutils.nodes import literal_block +from docutils.parsers.rst import Directive + + +class DoctestSkipDirective(Directive): + has_content = True + + def run(self): + # Check if there is any valid argument, and skip it. Currently only + # 'win32' is supported in astropy.tests.pytest_plugins. + if re.match('win32', self.content[0]): + self.content = self.content[2:] + code = '\n'.join(self.content) + return [literal_block(code, code)] + + +class DoctestOmitDirective(Directive): + 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 + + +def setup(app): + + app.add_directive('doctest-requires', DoctestRequiresDirective) + app.add_directive('doctest-skip', DoctestSkipDirective) + app.add_directive('doctest-skip-all', DoctestSkipDirective) + app.add_directive('doctest', DoctestSkipDirective, override=True) + # 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 + # belong in the documentation itself. + app.add_directive('testsetup', DoctestOmitDirective, override=True) + + return {'parallel_read_safe': True, + 'parallel_write_safe': True} diff -Nru pytest-doctestplus-0.7.0/pytest_doctestplus/utils.py pytest-doctestplus-0.9.0/pytest_doctestplus/utils.py --- pytest-doctestplus-0.7.0/pytest_doctestplus/utils.py 2020-05-20 14:56:16.000000000 +0000 +++ pytest-doctestplus-0.9.0/pytest_doctestplus/utils.py 2021-01-15 01:19:47.000000000 +0000 @@ -1,83 +1,22 @@ -import logging -import operator -import re -import subprocess -import sys -from distutils.version import LooseVersion +import importlib.util -logger = logging.getLogger(__name__) +import pkg_resources class ModuleChecker: - def __init__(self): - if LooseVersion(sys.version) < LooseVersion('3.4'): - import imp - self._find_module = imp.find_module - self._find_distribution = self._check_distribution - self.packages = self.get_packages() - else: - import importlib.util - import pkg_resources - self._find_module = importlib.util.find_spec - self._find_distribution = pkg_resources.require - self.packages = {} - - def get_packages(self): - packages = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']).decode().splitlines() - packages = [package.split('==') for package in packages if '==' in package] - return {name.lower(): version for name, version in packages} - - def compare_versions(self, v1, v2, op): - op_map = { - '<': operator.lt, - '<=': operator.le, - '>': operator.gt, - '>=': operator.ge, - '==': operator.eq, - } - if op not in op_map: - return False - op = op_map[op] - return op(LooseVersion(v1), LooseVersion(v2)) - - def _check_distribution(self, module): - """ - Python 2 (and <3.4) compatible version of pkg_resources.require. - But unlike pkg_resources.require it just checks whether package is - installed and has required version. - """ - match = re.match(r'([A-Za-z0-9-_]+)([^A-Za-z0-9-_]+)([\d.]+$)', module) - if not match: - return False - package, cmp, version = match.groups() - package = package.lower() - - if package in self.packages: - installed_version = self.packages[package] - if self.compare_versions(installed_version, version, cmp): - return True - else: - logger.warning( - "{} {} is installed. Version {}{} is required".format( - package, installed_version, cmp, version - ) - ) - return False - logger.warning("The '{}' distribution was not found and is required by the application".format(package)) - return False def find_module(self, module): """Search for modules specification.""" try: - return self._find_module(module) + return importlib.util.find_spec(module) except ImportError: return None def find_distribution(self, dist): """Search for distribution with specified version (eg 'numpy>=1.15').""" try: - return self._find_distribution(dist) - except Exception as e: + return pkg_resources.require(dist) + except Exception: return None def check(self, module): diff -Nru pytest-doctestplus-0.7.0/pytest_doctestplus/version.py pytest-doctestplus-0.9.0/pytest_doctestplus/version.py --- pytest-doctestplus-0.7.0/pytest_doctestplus/version.py 1970-01-01 00:00:00.000000000 +0000 +++ pytest-doctestplus-0.9.0/pytest_doctestplus/version.py 2021-01-15 01:19:55.000000000 +0000 @@ -0,0 +1,5 @@ +# coding: utf-8 +# file generated by setuptools_scm +# don't change, don't track in version control +version = '0.9.0' +version_tuple = (0, 9, 0) diff -Nru pytest-doctestplus-0.7.0/pytest_doctestplus.egg-info/PKG-INFO pytest-doctestplus-0.9.0/pytest_doctestplus.egg-info/PKG-INFO --- pytest-doctestplus-0.7.0/pytest_doctestplus.egg-info/PKG-INFO 2020-05-20 14:58:54.000000000 +0000 +++ pytest-doctestplus-0.9.0/pytest_doctestplus.egg-info/PKG-INFO 2021-01-15 01:19:55.000000000 +0000 @@ -1,8 +1,8 @@ -Metadata-Version: 1.2 +Metadata-Version: 2.1 Name: pytest-doctestplus -Version: 0.7.0 +Version: 0.9.0 Summary: Pytest plugin with advanced doctest features. -Home-page: https://astropy.org +Home-page: https://github.com/astropy/pytest-doctestplus Author: The Astropy Developers Author-email: astropy.team@gmail.com License: BSD @@ -16,7 +16,7 @@ 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/ + .. _astropy: https://astropy.org/ .. _reStructuredText: https://en.wikipedia.org/wiki/ReStructuredText @@ -57,7 +57,7 @@ $ git clone https://github.com/astropy/pytest-doctestplus $ cd pytest-doctestplus - $ python ./setup.py install + $ pip install . In either case, the plugin will automatically be registered for use with ``pytest``. @@ -155,6 +155,23 @@ >>> np.mean([]) # doctest: +IGNORE_WARNINGS np.nan + Showing warnings + ~~~~~~~~~~~~~~~~ + + If code in a doctest emits a warning and you want to make sure that warning is + shown, you can make use of the ``SHOW_WARNINGS`` flag. This is useful when + warnings are turned into errors by pytest, and also because by default warnings + are printed to stderr. This is the opposite from ``IGNORE_WARNINGS`` so + obviously the two flags should not be used together. For example: + + .. code-block:: python + + >>> import numpy as np + >>> np.mean([]) # doctest: +SHOW_WARNINGS + RuntimeWarning: Mean of empty slice. + RuntimeWarning: invalid value encountered in double_scalars + np.nan + Skipping Tests ~~~~~~~~~~~~~~ @@ -269,12 +286,23 @@ .. _pytest-remotedata: https://github.com/astropy/pytest-remotedata __ pytest-remotedata_ + Sphinx Compatibility + ~~~~~~~~~~~~~~~~~~~~ + + To use the additional directives when building your documentation with sphinx + you may want to enable the sphinx extension which registers these directives + with sphinx. Doing so ensures that sphinx correctly ignores these directives, + running the doctests with sphinx is not supported. To do this, add + ``'pytest_doctestplus.sphinx.doctestplus'`` to your ``extensions`` list in your + ``conf.py`` file. + + 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://github.com/astropy/pytest-doctestplus/workflows/Run%20unit%20tests/badge.svg + :target: https://github.com/astropy/pytest-doctestplus/actions + :alt: CI Status Questions, bug reports, and feature requests can be submitted on `github`_. @@ -294,6 +322,7 @@ Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 @@ -301,3 +330,4 @@ Classifier: Topic :: Software Development :: Testing Classifier: Topic :: Utilities Requires-Python: >=3.6 +Description-Content-Type: text/x-rst diff -Nru pytest-doctestplus-0.7.0/pytest_doctestplus.egg-info/requires.txt pytest-doctestplus-0.9.0/pytest_doctestplus.egg-info/requires.txt --- pytest-doctestplus-0.7.0/pytest_doctestplus.egg-info/requires.txt 2020-05-20 14:58:54.000000000 +0000 +++ pytest-doctestplus-0.9.0/pytest_doctestplus.egg-info/requires.txt 2021-01-15 01:19:55.000000000 +0000 @@ -1,2 +1,2 @@ -pytest>=4.0 -pip +pytest>=4.6 +setuptools>=30.3.0 diff -Nru pytest-doctestplus-0.7.0/pytest_doctestplus.egg-info/SOURCES.txt pytest-doctestplus-0.9.0/pytest_doctestplus.egg-info/SOURCES.txt --- pytest-doctestplus-0.7.0/pytest_doctestplus.egg-info/SOURCES.txt 2020-05-20 14:58:54.000000000 +0000 +++ pytest-doctestplus-0.9.0/pytest_doctestplus.egg-info/SOURCES.txt 2021-01-15 01:19:55.000000000 +0000 @@ -1,13 +1,21 @@ +.gitignore CHANGES.rst LICENSE.rst MANIFEST.in README.rst +pyproject.toml setup.cfg setup.py +tox.ini +.github/workflows/publish.yml +.github/workflows/python-tests.yml +licenses/README.rst +licenses/SYMPY_LICENSE.rst pytest_doctestplus/__init__.py pytest_doctestplus/output_checker.py pytest_doctestplus/plugin.py pytest_doctestplus/utils.py +pytest_doctestplus/version.py pytest_doctestplus.egg-info/PKG-INFO pytest_doctestplus.egg-info/SOURCES.txt pytest_doctestplus.egg-info/dependency_links.txt @@ -15,6 +23,8 @@ pytest_doctestplus.egg-info/not-zip-safe pytest_doctestplus.egg-info/requires.txt pytest_doctestplus.egg-info/top_level.txt +pytest_doctestplus/sphinx/__init__.py +pytest_doctestplus/sphinx/doctestplus.py tests/conftest.py tests/test_doctestplus.py tests/test_utils.py diff -Nru pytest-doctestplus-0.7.0/README.rst pytest-doctestplus-0.9.0/README.rst --- pytest-doctestplus-0.7.0/README.rst 2020-05-20 14:56:16.000000000 +0000 +++ pytest-doctestplus-0.9.0/README.rst 2021-01-15 01:19:47.000000000 +0000 @@ -8,7 +8,7 @@ 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/ +.. _astropy: https://astropy.org/ .. _reStructuredText: https://en.wikipedia.org/wiki/ReStructuredText @@ -49,7 +49,7 @@ $ git clone https://github.com/astropy/pytest-doctestplus $ cd pytest-doctestplus - $ python ./setup.py install + $ pip install . In either case, the plugin will automatically be registered for use with ``pytest``. @@ -147,6 +147,23 @@ >>> np.mean([]) # doctest: +IGNORE_WARNINGS np.nan +Showing warnings +~~~~~~~~~~~~~~~~ + +If code in a doctest emits a warning and you want to make sure that warning is +shown, you can make use of the ``SHOW_WARNINGS`` flag. This is useful when +warnings are turned into errors by pytest, and also because by default warnings +are printed to stderr. This is the opposite from ``IGNORE_WARNINGS`` so +obviously the two flags should not be used together. For example: + +.. code-block:: python + + >>> import numpy as np + >>> np.mean([]) # doctest: +SHOW_WARNINGS + RuntimeWarning: Mean of empty slice. + RuntimeWarning: invalid value encountered in double_scalars + np.nan + Skipping Tests ~~~~~~~~~~~~~~ @@ -261,12 +278,23 @@ .. _pytest-remotedata: https://github.com/astropy/pytest-remotedata __ pytest-remotedata_ +Sphinx Compatibility +~~~~~~~~~~~~~~~~~~~~ + +To use the additional directives when building your documentation with sphinx +you may want to enable the sphinx extension which registers these directives +with sphinx. Doing so ensures that sphinx correctly ignores these directives, +running the doctests with sphinx is not supported. To do this, add +``'pytest_doctestplus.sphinx.doctestplus'`` to your ``extensions`` list in your +``conf.py`` file. + + 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://github.com/astropy/pytest-doctestplus/workflows/Run%20unit%20tests/badge.svg + :target: https://github.com/astropy/pytest-doctestplus/actions + :alt: CI Status Questions, bug reports, and feature requests can be submitted on `github`_. diff -Nru pytest-doctestplus-0.7.0/setup.cfg pytest-doctestplus-0.9.0/setup.cfg --- pytest-doctestplus-0.7.0/setup.cfg 2020-05-20 14:58:54.000000000 +0000 +++ pytest-doctestplus-0.9.0/setup.cfg 2021-01-15 01:19:55.924952300 +0000 @@ -1,5 +1,49 @@ +[metadata] +name = pytest-doctestplus +url = https://github.com/astropy/pytest-doctestplus +author = The Astropy Developers +author_email = astropy.team@gmail.com +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 :: 3 + Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: Implementation :: CPython + Topic :: Software Development :: Testing + Topic :: Utilities +license = BSD +description = Pytest plugin with advanced doctest features. +long_description = file: README.rst +long_description_content_type = text/x-rst +keywords = doctest, rst, pytest, py.test + +[options] +zip_safe = False +packages = find: +python_requires = >=3.6 +setup_requires = + setuptools_scm +install_requires = + pytest>=4.6 + setuptools>=30.3.0 + +[options.entry_points] +pytest11 = + pytest_doctestplus = pytest_doctestplus.plugin + +[options.packages.find] +exclude = + tests + [tool:pytest] -minversion = 3.0 +minversion = 4.6 testpaths = tests pytest_doctestplus xfail_strict = true filterwarnings = diff -Nru pytest-doctestplus-0.7.0/setup.py pytest-doctestplus-0.9.0/setup.py --- pytest-doctestplus-0.7.0/setup.py 2020-05-20 14:57:37.000000000 +0000 +++ pytest-doctestplus-0.9.0/setup.py 2021-01-15 01:19:47.000000000 +0000 @@ -1,48 +1,6 @@ #!/usr/bin/env python -# Licensed under a 3-clause BSD style license - see LICENSE.rst -# -*- encoding: utf-8 -*- -from setuptools import setup, find_packages +import os +from setuptools import setup - -def readme(): - with open('README.rst') as ff: - return ff.read() - - -setup( - name='pytest-doctestplus', - version='0.7.0', - 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(exclude=['tests']), - include_package_data=True, - zip_safe=False, - 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 :: 3', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: Implementation :: CPython', - 'Topic :: Software Development :: Testing', - 'Topic :: Utilities', - ], - keywords=['doctest', 'rst', 'pytest', 'py.test'], - install_requires=['pytest>=4.0', 'pip'], - python_requires='>=3.6', - entry_points={ - 'pytest11': [ - 'pytest_doctestplus = pytest_doctestplus.plugin', - ], - }, -) +setup(use_scm_version={'write_to': os.path.join('pytest_doctestplus', 'version.py')}) diff -Nru pytest-doctestplus-0.7.0/tests/test_doctestplus.py pytest-doctestplus-0.9.0/tests/test_doctestplus.py --- pytest-doctestplus-0.7.0/tests/test_doctestplus.py 2020-05-20 14:56:16.000000000 +0000 +++ pytest-doctestplus-0.9.0/tests/test_doctestplus.py 2021-01-15 01:19:47.000000000 +0000 @@ -454,6 +454,72 @@ reprec.assertoutcome(failed=0, passed=1) +def test_show_warnings_module(testdir): + + p = testdir.makepyfile( + """ + def myfunc(): + ''' + >>> import warnings + >>> warnings.warn('A warning occurred', UserWarning) # doctest: +SHOW_WARNINGS + UserWarning: A warning occurred + ''' + pass + """) + reprec = testdir.inline_run(p, "--doctest-plus", "-W error") + reprec.assertoutcome(failed=0, passed=1) + + # Make sure it fails if warning message is missing + p = testdir.makepyfile( + """ + def myfunc(): + ''' + >>> import warnings + >>> warnings.warn('A warning occurred', UserWarning) # doctest: +SHOW_WARNINGS + ''' + pass + """) + reprec = testdir.inline_run(p, "--doctest-plus", "-W error") + reprec.assertoutcome(failed=1, passed=0) + + +def test_show_warnings_rst(testdir): + + p = testdir.makefile(".rst", + """ + :: + >>> import warnings + >>> warnings.warn('A warning occurred', UserWarning) # doctest: +SHOW_WARNINGS + UserWarning: A warning occurred + """) + reprec = testdir.inline_run(p, "--doctest-plus", "--doctest-rst", + "--text-file-format=rst", "-W error") + reprec.assertoutcome(failed=0, passed=1) + + # Make sure it fails if warning message is missing + p = testdir.makefile(".rst", + """ + :: + >>> import warnings + >>> warnings.warn('A warning occurred', UserWarning) # doctest: +SHOW_WARNINGS + """) + reprec = testdir.inline_run(p, "--doctest-plus", "--doctest-rst", + "--text-file-format=rst", "-W error") + reprec.assertoutcome(failed=1, passed=0) + + # Make sure it fails if warning message is missing + p = testdir.makefile(".rst", + """ + :: + >>> import warnings + >>> warnings.warn('A warning occurred', UserWarning) # doctest: +SHOW_WARNINGS + Warning: Another warning occurred + """) + reprec = testdir.inline_run(p, "--doctest-plus", "--doctest-rst", + "--text-file-format=rst", "-W error") + reprec.assertoutcome(failed=1, passed=0) + + def test_doctest_glob(testdir): testdir.makefile( '.rst', diff -Nru pytest-doctestplus-0.7.0/tests/test_utils.py pytest-doctestplus-0.9.0/tests/test_utils.py --- pytest-doctestplus-0.7.0/tests/test_utils.py 2019-11-15 18:09:36.000000000 +0000 +++ pytest-doctestplus-0.9.0/tests/test_utils.py 2021-01-15 01:19:47.000000000 +0000 @@ -11,15 +11,3 @@ c = ModuleChecker() assert c.check('pytest>1.0') assert not c.check('foobar>1.0') - - def test_check_distribution(self): - c = ModuleChecker() - # in python3.4+ packages attribute will not be populated - # because it calls 'pip freeze' which is slow - if not c.packages: - c.packages = c.get_packages() - # after this we will be able to test _check_distribution even in - # python3.4+ environment - assert c._check_distribution('pytest>1.0') - assert not c._check_distribution('pytest<1.0') - assert not c._check_distribution('foobar>1.0') diff -Nru pytest-doctestplus-0.7.0/tox.ini pytest-doctestplus-0.9.0/tox.ini --- pytest-doctestplus-0.7.0/tox.ini 1970-01-01 00:00:00.000000000 +0000 +++ pytest-doctestplus-0.9.0/tox.ini 2021-01-15 01:19:47.000000000 +0000 @@ -0,0 +1,35 @@ +[tox] +envlist = + py{36,37,38,39}-test + codestyle +requires = + setuptools >= 30.3.0 + pip >= 19.3.1 +isolated_build = true + +[testenv] +changedir = .tmp/{envname} +description = run tests +deps = + pytest46: pytest==4.6.* + pytest50: pytest==5.0.* + pytest51: pytest==5.1.* + pytest52: pytest==5.2.* + pytest53: pytest==5.3.* + pytest60: pytest==6.0.* + pytest61: pytest==6.1.* + pytestdev: git+https://github.com/pytest-dev/pytest#egg=pytest + +commands = + pip freeze + pytest {toxinidir}/tests {posargs} + pytest {toxinidir}/tests --doctest-plus {posargs} + pytest {toxinidir}/tests --doctest-plus --doctest-rst {posargs} + pytest {toxinidir}/tests --doctest-plus --doctest-rst --text-file-format=tex {posargs} + +[testenv:codestyle] +changedir = +skip_install = true +description = check code style, e.g. with flake8 +deps = flake8 +commands = flake8 pytest_doctestplus --count