[Pytest-commit] commit/pytest: 3 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Feb 26 21:59:58 CET 2015


3 new commits in pytest:

https://bitbucket.org/hpk42/pytest/commits/bac853daacf5/
Changeset:   bac853daacf5
Branch:      ignore-doctest-import-errors
User:        cpcloud
Date:        2015-02-08 06:25:23+00:00
Summary:     Add option to ignore import errors in doctests
Affected #:  1 file

diff -r fa62c5c63c2fb5870852676d8d8899b9656214fd -r bac853daacf5d2ba3d1ca1e5084200ecde76d88d _pytest/doctest.py
--- a/_pytest/doctest.py
+++ b/_pytest/doctest.py
@@ -17,6 +17,10 @@
         action="store", default="test*.txt", metavar="pat",
         help="doctests file matching pattern, default: test*.txt",
         dest="doctestglob")
+    group.addoption("--doctest-ignore-import-errors",
+        action="store_true", default=False,
+        help="ignore doctest ImportErrors",
+        dest="doctest_ignore_import_errors")
 
 def pytest_collect_file(path, parent):
     config = parent.config
@@ -130,7 +134,13 @@
         if self.fspath.basename == "conftest.py":
             module = self.config._conftest.importconftest(self.fspath)
         else:
-            module = self.fspath.pyimport()
+            try:
+                module = self.fspath.pyimport()
+            except ImportError:
+                if self.config.getvalue('doctest_ignore_import_errors'):
+                    pytest.skip('unable to import module %r' % self.fspath)
+                else:
+                    raise
         # satisfy `FixtureRequest` constructor...
         self.funcargs = {}
         self._fixtureinfo = FuncFixtureInfo((), [], {})
@@ -138,9 +148,9 @@
         doctest_globals = dict(getfixture=fixture_request.getfuncargvalue)
         # uses internal doctest module parsing mechanism
         finder = doctest.DocTestFinder()
-        optionflags= get_optionflags(self)
+        optionflags = get_optionflags(self)
         runner = doctest.DebugRunner(verbose=0, optionflags=optionflags)
         for test in finder.find(module, module.__name__,
                                 extraglobs=doctest_globals):
-            if test.examples: # skip empty doctests
+            if test.examples:  # skip empty doctests
                 yield DoctestItem(test.name, self, runner, test)


https://bitbucket.org/hpk42/pytest/commits/2b5d32cec885/
Changeset:   2b5d32cec885
Branch:      ignore-doctest-import-errors
User:        cpcloud
Date:        2015-02-26 17:39:36+00:00
Summary:     Add test for command line usage
Affected #:  1 file

diff -r bac853daacf5d2ba3d1ca1e5084200ecde76d88d -r 2b5d32cec885a1faee1f9be15807a455d5534918 testing/test_doctest.py
--- a/testing/test_doctest.py
+++ b/testing/test_doctest.py
@@ -349,3 +349,19 @@
         """)
         reprec = testdir.inline_run(p, "--doctest-glob=x*.txt")
         reprec.assertoutcome(failed=1, passed=0)
+
+    def test_ignore_import_errors_on_doctest(self, testdir):
+        p = testdir.makepyfile("""
+            import asdf
+
+            def add_one(x):
+                '''
+                >>> add_one(1)
+                2
+                '''
+                return x + 1
+        """)
+
+        reprec = testdir.inline_run(p, "--doctest-modules",
+                                    "--doctest-ignore-import-errors")
+        reprec.assertoutcome(skipped=1, failed=1, passed=0)


https://bitbucket.org/hpk42/pytest/commits/eeaef9601d3f/
Changeset:   eeaef9601d3f
User:        hpk42
Date:        2015-02-26 20:59:54+00:00
Summary:     Merged in cpcloud/pytest/ignore-doctest-import-errors (pull request #243)

Add option to ignore import errors in doctests
Affected #:  2 files

diff -r 6104c7ea0dccd13b892fa021a2fc989f60a8ff59 -r eeaef9601d3f2996c3bbbc4c0301a859d8bc35b5 _pytest/doctest.py
--- a/_pytest/doctest.py
+++ b/_pytest/doctest.py
@@ -17,6 +17,10 @@
         action="store", default="test*.txt", metavar="pat",
         help="doctests file matching pattern, default: test*.txt",
         dest="doctestglob")
+    group.addoption("--doctest-ignore-import-errors",
+        action="store_true", default=False,
+        help="ignore doctest ImportErrors",
+        dest="doctest_ignore_import_errors")
 
 def pytest_collect_file(path, parent):
     config = parent.config
@@ -130,7 +134,13 @@
         if self.fspath.basename == "conftest.py":
             module = self.config._conftest.importconftest(self.fspath)
         else:
-            module = self.fspath.pyimport()
+            try:
+                module = self.fspath.pyimport()
+            except ImportError:
+                if self.config.getvalue('doctest_ignore_import_errors'):
+                    pytest.skip('unable to import module %r' % self.fspath)
+                else:
+                    raise
         # satisfy `FixtureRequest` constructor...
         self.funcargs = {}
         self._fixtureinfo = FuncFixtureInfo((), [], {})
@@ -138,9 +148,9 @@
         doctest_globals = dict(getfixture=fixture_request.getfuncargvalue)
         # uses internal doctest module parsing mechanism
         finder = doctest.DocTestFinder()
-        optionflags= get_optionflags(self)
+        optionflags = get_optionflags(self)
         runner = doctest.DebugRunner(verbose=0, optionflags=optionflags)
         for test in finder.find(module, module.__name__,
                                 extraglobs=doctest_globals):
-            if test.examples: # skip empty doctests
+            if test.examples:  # skip empty doctests
                 yield DoctestItem(test.name, self, runner, test)

diff -r 6104c7ea0dccd13b892fa021a2fc989f60a8ff59 -r eeaef9601d3f2996c3bbbc4c0301a859d8bc35b5 testing/test_doctest.py
--- a/testing/test_doctest.py
+++ b/testing/test_doctest.py
@@ -341,3 +341,19 @@
         """)
         reprec = testdir.inline_run(p, "--doctest-glob=x*.txt")
         reprec.assertoutcome(failed=1, passed=0)
+
+    def test_ignore_import_errors_on_doctest(self, testdir):
+        p = testdir.makepyfile("""
+            import asdf
+
+            def add_one(x):
+                '''
+                >>> add_one(1)
+                2
+                '''
+                return x + 1
+        """)
+
+        reprec = testdir.inline_run(p, "--doctest-modules",
+                                    "--doctest-ignore-import-errors")
+        reprec.assertoutcome(skipped=1, failed=1, passed=0)

Repository URL: https://bitbucket.org/hpk42/pytest/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the pytest-commit mailing list