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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Oct 9 17:05:52 CEST 2014


5 new commits in pytest:

https://bitbucket.org/hpk42/pytest/commits/23ce9d676118/
Changeset:   23ce9d676118
User:        Holger Peters
Date:        2014-10-08 12:31:17+00:00
Summary:     Add configuration option for doctest flags
Affected #:  2 files

diff -r 63ee1c59835ab6b44c868a410d3d40f9bcebb843 -r 23ce9d6761185623434a1a58809203e324ff0280 _pytest/doctest.py
--- a/_pytest/doctest.py
+++ b/_pytest/doctest.py
@@ -6,6 +6,8 @@
 from py._code.code import TerminalRepr, ReprFileLocation
 
 def pytest_addoption(parser):
+    parser.addini('doctest_optionflags', 'option flags for doctests',
+        type="args", default=["ELLIPSIS"])
     group = parser.getgroup("collect")
     group.addoption("--doctest-modules",
         action="store_true", default=False,
@@ -87,6 +89,27 @@
     def reportinfo(self):
         return self.fspath, None, "[doctest] %s" % self.name
 
+def _get_flag_lookup():
+    import doctest
+    return dict(DONT_ACCEPT_TRUE_FOR_1=doctest.DONT_ACCEPT_TRUE_FOR_1,
+                DONT_ACCEPT_BLANKLINE=doctest.DONT_ACCEPT_BLANKLINE,
+                NORMALIZE_WHITESPACE=doctest.NORMALIZE_WHITESPACE,
+                ELLIPSIS=doctest.ELLIPSIS,
+                IGNORE_EXCEPTION_DETAIL=doctest.IGNORE_EXCEPTION_DETAIL,
+                COMPARISON_FLAGS=doctest.COMPARISON_FLAGS)
+
+def get_optionflags(parent):
+    import doctest
+    optionflags_str = parent.config.getini("doctest_optionflags")
+    flag_lookup_table = _get_flag_lookup()
+    if not optionflags_str:
+        return doctest.ELLIPSIS
+
+    flag_acc = 0
+    for flag in optionflags_str:
+        flag_acc |= flag_lookup_table[flag]
+    return flag_acc
+
 class DoctestTextfile(DoctestItem, pytest.File):
     def runtest(self):
         import doctest
@@ -101,7 +124,7 @@
         fixture_request._fillfixtures()
         failed, tot = doctest.testfile(
             str(self.fspath), module_relative=False,
-            optionflags=doctest.ELLIPSIS,
+            optionflags=get_optionflags(self),
             extraglobs=dict(getfixture=fixture_request.getfuncargvalue),
             raise_on_error=True, verbose=0)
 
@@ -119,7 +142,8 @@
         doctest_globals = dict(getfixture=fixture_request.getfuncargvalue)
         # uses internal doctest module parsing mechanism
         finder = doctest.DocTestFinder()
-        runner = doctest.DebugRunner(verbose=0, optionflags=doctest.ELLIPSIS)
+        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

diff -r 63ee1c59835ab6b44c868a410d3d40f9bcebb843 -r 23ce9d6761185623434a1a58809203e324ff0280 testing/test_doctest.py
--- a/testing/test_doctest.py
+++ b/testing/test_doctest.py
@@ -289,3 +289,37 @@
         """)
         reprec = testdir.inline_run(p, "--doctest-modules")
         reprec.assertoutcome(failed=1, passed=1)
+
+    def test_ignored_whitespace(self, testdir):
+        testdir.makeini("""
+            [pytest]
+            doctest_optionflags = ELLIPSIS NORMALIZE_WHITESPACE
+        """)
+        p = testdir.makepyfile("""
+            class MyClass:
+                '''
+                >>> a = "foo    "
+                >>> print(a)
+                foo
+                '''
+                pass
+        """)
+        reprec = testdir.inline_run(p, "--doctest-modules")
+        reprec.assertoutcome(passed=1)
+
+    def test_non_ignored_whitespace(self, testdir):
+        testdir.makeini("""
+            [pytest]
+            doctest_optionflags = ELLIPSIS
+        """)
+        p = testdir.makepyfile("""
+            class MyClass:
+                '''
+                >>> a = "foo    "
+                >>> print(a)
+                foo
+                '''
+                pass
+        """)
+        reprec = testdir.inline_run(p, "--doctest-modules")
+        reprec.assertoutcome(failed=1, passed=0)


https://bitbucket.org/hpk42/pytest/commits/f13f826c865f/
Changeset:   f13f826c865f
User:        Holger Peters
Date:        2014-10-08 13:48:41+00:00
Summary:     Add documentation for doctest flags and remove dead code
Affected #:  4 files

diff -r 23ce9d6761185623434a1a58809203e324ff0280 -r f13f826c865f5fdea9a8bf632e97a88e86991f69 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,8 @@
 Unreleased
 ----------
 
+- add a doctest option for doctest flags
+
 - Improve assertion failure reporting on iterables, by using ndiff and pprint.
 
 - removed outdated japanese docs from source tree.

diff -r 23ce9d6761185623434a1a58809203e324ff0280 -r f13f826c865f5fdea9a8bf632e97a88e86991f69 _pytest/doctest.py
--- a/_pytest/doctest.py
+++ b/_pytest/doctest.py
@@ -102,9 +102,6 @@
     import doctest
     optionflags_str = parent.config.getini("doctest_optionflags")
     flag_lookup_table = _get_flag_lookup()
-    if not optionflags_str:
-        return doctest.ELLIPSIS
-
     flag_acc = 0
     for flag in optionflags_str:
         flag_acc |= flag_lookup_table[flag]

diff -r 23ce9d6761185623434a1a58809203e324ff0280 -r f13f826c865f5fdea9a8bf632e97a88e86991f69 doc/en/customize.txt
--- a/doc/en/customize.txt
+++ b/doc/en/customize.txt
@@ -126,3 +126,8 @@
    derived class.
 
    See :ref:`change naming conventions` for examples.
+
+.. confval:: doctest_optionflags
+
+   One or more doctest flag names from the standard ``doctest`` module.
+   `See how py.test handles doctests <doctest.html>`_.

diff -r 23ce9d6761185623434a1a58809203e324ff0280 -r f13f826c865f5fdea9a8bf632e97a88e86991f69 doc/en/doctest.txt
--- a/doc/en/doctest.txt
+++ b/doc/en/doctest.txt
@@ -60,3 +60,12 @@
 
 Also, :ref:`usefixtures` and :ref:`autouse` fixtures are supported
 when executing text doctest files.
+
+The standard ``doctest`` module provides some setting flags to configure the
+strictness of doctest tests. In py.test You can enable those flags those flags
+using the configuration file. To make pytest ignore trailing whitespaces and
+ignore lengthy exception stack traces you can just write::
+
+    # content of pytest.ini
+    [pytest]
+    doctest_optionflags= NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL


https://bitbucket.org/hpk42/pytest/commits/42fa30934045/
Changeset:   42fa30934045
User:        Holger Peters
Date:        2014-10-08 13:54:08+00:00
Summary:     Add a doctest for module docstrings
Affected #:  1 file

diff -r f13f826c865f5fdea9a8bf632e97a88e86991f69 -r 42fa30934045df1ef34d4b99fa42369a97fb97f4 testing/test_doctest.py
--- a/testing/test_doctest.py
+++ b/testing/test_doctest.py
@@ -323,3 +323,29 @@
         """)
         reprec = testdir.inline_run(p, "--doctest-modules")
         reprec.assertoutcome(failed=1, passed=0)
+
+    def test_ignored_whitespace_glob(self, testdir):
+        testdir.makeini("""
+            [pytest]
+            doctest_optionflags = ELLIPSIS NORMALIZE_WHITESPACE
+        """)
+        p = testdir.maketxtfile(xdoc="""
+            >>> a = "foo    "
+            >>> print(a)
+            foo
+        """)
+        reprec = testdir.inline_run(p, "--doctest-glob=x*.txt")
+        reprec.assertoutcome(passed=1)
+
+    def test_non_ignored_whitespace_glob(self, testdir):
+        testdir.makeini("""
+            [pytest]
+            doctest_optionflags = ELLIPSIS
+        """)
+        p = testdir.maketxtfile(xdoc="""
+            >>> a = "foo    "
+            >>> print(a)
+            foo
+        """)
+        reprec = testdir.inline_run(p, "--doctest-glob=x*.txt")
+        reprec.assertoutcome(failed=1, passed=0)


https://bitbucket.org/hpk42/pytest/commits/6528e73b1e67/
Changeset:   6528e73b1e67
User:        Holger Peters
Date:        2014-10-09 14:59:42+00:00
Summary:     link fix: Use restructured text :doc: link instead of html link
Affected #:  1 file

diff -r 42fa30934045df1ef34d4b99fa42369a97fb97f4 -r 6528e73b1e67a23ee6d74a9ea66c7eb95035c093 doc/en/customize.txt
--- a/doc/en/customize.txt
+++ b/doc/en/customize.txt
@@ -130,4 +130,4 @@
 .. confval:: doctest_optionflags
 
    One or more doctest flag names from the standard ``doctest`` module.
-   `See how py.test handles doctests <doctest.html>`_.
+   :doc:`See how py.test handles doctests <doctest>`.


https://bitbucket.org/hpk42/pytest/commits/6c340d023e4b/
Changeset:   6c340d023e4b
User:        hpk42
Date:        2014-10-09 15:05:48+00:00
Summary:     Merged in HolgerPeters/pytest (pull request #221)

Make doctest flags configurable
Affected #:  5 files

diff -r 0f4f922372c86919ea2266bbc0cdb151b645b13d -r 6c340d023e4b010e71acc2e94c0120dfb5161b24 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -14,6 +14,8 @@
 2.6.4.dev
 ----------
 
+- add a doctest option for doctest flags
+
 - Improve assertion failure reporting on iterables, by using ndiff and pprint.
 
 - removed outdated japanese docs from source tree.

diff -r 0f4f922372c86919ea2266bbc0cdb151b645b13d -r 6c340d023e4b010e71acc2e94c0120dfb5161b24 _pytest/doctest.py
--- a/_pytest/doctest.py
+++ b/_pytest/doctest.py
@@ -6,6 +6,8 @@
 from py._code.code import TerminalRepr, ReprFileLocation
 
 def pytest_addoption(parser):
+    parser.addini('doctest_optionflags', 'option flags for doctests',
+        type="args", default=["ELLIPSIS"])
     group = parser.getgroup("collect")
     group.addoption("--doctest-modules",
         action="store_true", default=False,
@@ -87,6 +89,24 @@
     def reportinfo(self):
         return self.fspath, None, "[doctest] %s" % self.name
 
+def _get_flag_lookup():
+    import doctest
+    return dict(DONT_ACCEPT_TRUE_FOR_1=doctest.DONT_ACCEPT_TRUE_FOR_1,
+                DONT_ACCEPT_BLANKLINE=doctest.DONT_ACCEPT_BLANKLINE,
+                NORMALIZE_WHITESPACE=doctest.NORMALIZE_WHITESPACE,
+                ELLIPSIS=doctest.ELLIPSIS,
+                IGNORE_EXCEPTION_DETAIL=doctest.IGNORE_EXCEPTION_DETAIL,
+                COMPARISON_FLAGS=doctest.COMPARISON_FLAGS)
+
+def get_optionflags(parent):
+    import doctest
+    optionflags_str = parent.config.getini("doctest_optionflags")
+    flag_lookup_table = _get_flag_lookup()
+    flag_acc = 0
+    for flag in optionflags_str:
+        flag_acc |= flag_lookup_table[flag]
+    return flag_acc
+
 class DoctestTextfile(DoctestItem, pytest.File):
     def runtest(self):
         import doctest
@@ -101,7 +121,7 @@
         fixture_request._fillfixtures()
         failed, tot = doctest.testfile(
             str(self.fspath), module_relative=False,
-            optionflags=doctest.ELLIPSIS,
+            optionflags=get_optionflags(self),
             extraglobs=dict(getfixture=fixture_request.getfuncargvalue),
             raise_on_error=True, verbose=0)
 
@@ -119,7 +139,8 @@
         doctest_globals = dict(getfixture=fixture_request.getfuncargvalue)
         # uses internal doctest module parsing mechanism
         finder = doctest.DocTestFinder()
-        runner = doctest.DebugRunner(verbose=0, optionflags=doctest.ELLIPSIS)
+        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

diff -r 0f4f922372c86919ea2266bbc0cdb151b645b13d -r 6c340d023e4b010e71acc2e94c0120dfb5161b24 doc/en/customize.txt
--- a/doc/en/customize.txt
+++ b/doc/en/customize.txt
@@ -126,3 +126,8 @@
    derived class.
 
    See :ref:`change naming conventions` for examples.
+
+.. confval:: doctest_optionflags
+
+   One or more doctest flag names from the standard ``doctest`` module.
+   :doc:`See how py.test handles doctests <doctest>`.

diff -r 0f4f922372c86919ea2266bbc0cdb151b645b13d -r 6c340d023e4b010e71acc2e94c0120dfb5161b24 doc/en/doctest.txt
--- a/doc/en/doctest.txt
+++ b/doc/en/doctest.txt
@@ -60,3 +60,12 @@
 
 Also, :ref:`usefixtures` and :ref:`autouse` fixtures are supported
 when executing text doctest files.
+
+The standard ``doctest`` module provides some setting flags to configure the
+strictness of doctest tests. In py.test You can enable those flags those flags
+using the configuration file. To make pytest ignore trailing whitespaces and
+ignore lengthy exception stack traces you can just write::
+
+    # content of pytest.ini
+    [pytest]
+    doctest_optionflags= NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL

diff -r 0f4f922372c86919ea2266bbc0cdb151b645b13d -r 6c340d023e4b010e71acc2e94c0120dfb5161b24 testing/test_doctest.py
--- a/testing/test_doctest.py
+++ b/testing/test_doctest.py
@@ -289,3 +289,63 @@
         """)
         reprec = testdir.inline_run(p, "--doctest-modules")
         reprec.assertoutcome(failed=1, passed=1)
+
+    def test_ignored_whitespace(self, testdir):
+        testdir.makeini("""
+            [pytest]
+            doctest_optionflags = ELLIPSIS NORMALIZE_WHITESPACE
+        """)
+        p = testdir.makepyfile("""
+            class MyClass:
+                '''
+                >>> a = "foo    "
+                >>> print(a)
+                foo
+                '''
+                pass
+        """)
+        reprec = testdir.inline_run(p, "--doctest-modules")
+        reprec.assertoutcome(passed=1)
+
+    def test_non_ignored_whitespace(self, testdir):
+        testdir.makeini("""
+            [pytest]
+            doctest_optionflags = ELLIPSIS
+        """)
+        p = testdir.makepyfile("""
+            class MyClass:
+                '''
+                >>> a = "foo    "
+                >>> print(a)
+                foo
+                '''
+                pass
+        """)
+        reprec = testdir.inline_run(p, "--doctest-modules")
+        reprec.assertoutcome(failed=1, passed=0)
+
+    def test_ignored_whitespace_glob(self, testdir):
+        testdir.makeini("""
+            [pytest]
+            doctest_optionflags = ELLIPSIS NORMALIZE_WHITESPACE
+        """)
+        p = testdir.maketxtfile(xdoc="""
+            >>> a = "foo    "
+            >>> print(a)
+            foo
+        """)
+        reprec = testdir.inline_run(p, "--doctest-glob=x*.txt")
+        reprec.assertoutcome(passed=1)
+
+    def test_non_ignored_whitespace_glob(self, testdir):
+        testdir.makeini("""
+            [pytest]
+            doctest_optionflags = ELLIPSIS
+        """)
+        p = testdir.maketxtfile(xdoc="""
+            >>> a = "foo    "
+            >>> print(a)
+            foo
+        """)
+        reprec = testdir.inline_run(p, "--doctest-glob=x*.txt")
+        reprec.assertoutcome(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