Allow pytest 3.x to use plugin for doctests in .rst files.
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>
Thu, 12 Jan 2017 02:59:16 +0000 (21:59 -0500)
committerOle Streicher <olebole@debian.org>
Wed, 25 Jan 2017 15:17:26 +0000 (15:17 +0000)
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

astropy/tests/pytest_plugins.py
astropy/tests/tests/test_runner.py
setup.cfg

index 27b683d211fef56ecf50a20022a9a5dc9fe3acd5..64f7b74d08455acb799aaf8511f633f1db50f999 100644 (file)
@@ -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,
index a147cd97c62746ef841c9c7114aee3526ad8c36a..0642c7f82108d66e753d6cd58031ec0b5cb822c5 100644 (file)
@@ -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):
             """
index 206e6f8cce3af16fbe5de475e5fc701f8d2b5d36..dc1531803f6005ccfcbe69e7f27703732bcaaaee 100644 (file)
--- 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