From: Marten van Kerkwijk Date: Thu, 12 Jan 2017 02:59:16 +0000 (-0500) Subject: Allow pytest 3.x to use plugin for doctests in .rst files. X-Git-Tag: archive/raspbian/2.0.2-2+rpi1~1^2^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=ce36aed26b60ee5b73cadb155a1022bfb668adf3;p=python-astropy.git Allow pytest 3.x to use plugin for doctests in .rst files. Pull request: https://github.com/astropy/astropy/pull/5688 Gbp-Pq: Name Allow-pytest-3.x-to-use-plugin-for-doctests-in-.rst-files.patch --- diff --git a/astropy/tests/pytest_plugins.py b/astropy/tests/pytest_plugins.py index 27b683d..64f7b74 100644 --- a/astropy/tests/pytest_plugins.py +++ b/astropy/tests/pytest_plugins.py @@ -180,7 +180,8 @@ def pytest_configure(config): # uses internal doctest module parsing mechanism finder = DocTestFinderPlus() - runner = doctest.DebugRunner(verbose=False, optionflags=opts) + runner = doctest.DebugRunner(verbose=False, optionflags=opts, + checker=AstropyOutputChecker()) for test in finder.find(module): if test.examples: # skip empty doctests if config.getvalue("remote_data") != 'any': @@ -191,21 +192,11 @@ def pytest_configure(config): yield doctest_plugin.DoctestItem( test.name, self, runner, test) - # This is for py.test prior to 2.4.0 - def runtest(self): - return - - class DocTestTextfilePlus(doctest_plugin.DoctestTextfile): + class DocTestTextfilePlus(doctest_plugin.DoctestItem, pytest.Module): def runtest(self): # satisfy `FixtureRequest` constructor... self.funcargs = {} - try: - self._fixtureinfo = doctest_plugin.FuncFixtureInfo((), [], {}) - fixture_request = doctest_plugin.FixtureRequest(self) - except AttributeError: # pytest >= 2.8.0 - python_plugin = config.pluginmanager.getplugin('python') - self._fixtureinfo = python_plugin.FuncFixtureInfo((), [], {}) - fixture_request = python_plugin.FixtureRequest(self) + fixture_request = doctest_plugin._setup_fixtures(self) failed, tot = doctest.testfile( str(self.fspath), module_relative=False, diff --git a/astropy/tests/tests/test_runner.py b/astropy/tests/tests/test_runner.py index a147cd9..0642c7f 100644 --- a/astropy/tests/tests/test_runner.py +++ b/astropy/tests/tests/test_runner.py @@ -1,9 +1,11 @@ -from astropy.tests.runner import TestRunner, TestRunnerBase, keyword +from astropy.tests.runner import TestRunner as T_Runner +from astropy.tests.runner import TestRunnerBase as T_RunnerBase +from astropy.tests.runner import keyword from astropy.tests.helper import pytest def test_disable_kwarg(): - class no_remote_data(TestRunner): + class no_remote_data(T_Runner): @keyword() def remote_data(self, remote_data, kwargs): return NotImplemented @@ -14,13 +16,13 @@ def test_disable_kwarg(): def test_wrong_kwarg(): - r = TestRunner('.') + r = T_Runner('.') with pytest.raises(TypeError): r.run_tests(spam='eggs') def test_invalid_kwarg(): - class bad_return(TestRunnerBase): + class bad_return(T_RunnerBase): @keyword() def remote_data(self, remote_data, kwargs): return 'bob' @@ -31,7 +33,7 @@ def test_invalid_kwarg(): def test_new_kwarg(): - class Spam(TestRunnerBase): + class Spam(T_RunnerBase): @keyword() def spam(self, spam, kwargs): return [spam] @@ -44,7 +46,7 @@ def test_new_kwarg(): def test_priority(): - class Spam(TestRunnerBase): + class Spam(T_RunnerBase): @keyword() def spam(self, spam, kwargs): return [spam] @@ -61,7 +63,7 @@ def test_priority(): def test_docs(): - class Spam(TestRunnerBase): + class Spam(T_RunnerBase): @keyword() def spam(self, spam, kwargs): """ diff --git a/setup.cfg b/setup.cfg index 206e6f8..dc15318 100644 --- a/setup.cfg +++ b/setup.cfg @@ -12,7 +12,7 @@ all_files = 1 upload-dir = docs/_build/html show-response = 1 -[pytest] +[tool:pytest] minversion = 2.3.3 norecursedirs = ".tox" "build" "docs[\/]_build" "astropy[\/]extern" "astropy[\/]utils[\/]compat[\/]futures" doctest_plus = enabled