Commits

Ronny Pfannschmidt  committed d105b8d

push some patches

  • Participants
  • Parent commits cfa76fd

Comments (0)

Files changed (5)

File fnmatch-python-test-names

 # HG changeset patch
-# Parent 24fd2ff2e4c2a8bcb868fc5f25531f8880b46d95
+# Parent 4a015a903b1650c15fed3c8283f67f8c46271127
 support using fnmatch wildcards for the python_classes/functions filters
 
 diff --git a/CHANGELOG b/CHANGELOG
 --- a/CHANGELOG
 +++ b/CHANGELOG
-@@ -30,6 +30,7 @@ Changes between 2.1.3 and 2.2.0
- - fix issue74: pyarg module names are now checked against imp.find_module false positives
- - fix compatibility with twisted/trial-11.1.0 use cases
+@@ -32,6 +32,7 @@ Changes between 2.1.3 and 2.2.0
+ - simplify Node.listchain
+ - simplify junitxml output code by relying on py.xml
  - add support for skip properties on unittest classes and functions
 +- add support for fnmatch based matching of python_classes/python_functions
  
  
      def collect(self):
          # NB. we avoid random getattrs and peek in the __dict__ instead
+diff --git a/doc/customize.txt b/doc/customize.txt
+--- a/doc/customize.txt
++++ b/doc/customize.txt
+@@ -112,13 +112,13 @@ Builtin configuration file options
+ 
+ .. confval:: python_classes
+ 
+-   One or more name prefixes determining which test classes
+-   are considered as test modules.
++   One or more name prefixes or fnmatch patterns determining
++   which test classes are considered as test modules.
+ 
+ .. confval:: python_functions
+ 
+-   One or more name prefixes determining which test functions
+-   and methods are considered as test modules.
++   One or more name prefixes or fnmatch patterns determining
++   which test functions and methods are considered as test modules.
+ 
+    See :ref:`change naming conventions` for examples.
+ 
+diff --git a/doc/example/pythoncollection.txt b/doc/example/pythoncollection.txt
+--- a/doc/example/pythoncollection.txt
++++ b/doc/example/pythoncollection.txt
+@@ -25,8 +25,8 @@ the :confval:`python_files`, :confval:`p
+     # can also be defined in in tox.ini or pytest.ini file
+     [pytest]
+     python_files=check_*.py
+-    python_classes=Check
+-    python_functions=check
++    python_classes=Check Describe
++    python_functions=check *_should_*
+ 
+ This would make py.test look for ``check_`` prefixes in
+ Python filenames, ``Check`` prefixes in classes and ``check`` prefixes
+@@ -39,6 +39,10 @@ in functions and classes.  For example, 
+         def check_complex(self):
+             pass
+ 
++    class DescribeMyApp:
++        def user_should_login(self):
++            pass
++
+ then the test collection looks like this::
+ 
+     $ py.test --collectonly
 diff --git a/testing/test_python.py b/testing/test_python.py
 --- a/testing/test_python.py
 +++ b/testing/test_python.py

File junitxml-pyxml

-# HG changeset patch
-# Parent 8a6038f9310b0686dc4a98453f03848aac775df3
-use py.xml for generating the junitxml files
-
-diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py
---- a/_pytest/junitxml.py
-+++ b/_pytest/junitxml.py
-@@ -25,6 +25,10 @@ except NameError:
-     long = int
- 
- 
-+class Junit(py.xml.Namespace):
-+    pass
-+
-+
- # We need to get the subset of the invalid unicode ranges according to
- # XML 1.0 which are valid in this python build.  Hence we calculate
- # this dynamically instead of hardcoding it.  The spec range of valid
-@@ -40,6 +44,14 @@ illegal_xml_re = re.compile(unicode('[%s
- del _illegal_unichrs
- del _illegal_ranges
- 
-+def bin_xml_escape(arg):
-+    def repl(matchobj):
-+        i = ord(matchobj.group())
-+        if i <= 0xFF:
-+            return unicode('#x%02X') % i
-+        else:
-+            return unicode('#x%04X') % i
-+    return illegal_xml_re.sub(repl, py.xml.escape(arg))
- 
- def pytest_addoption(parser):
-     group = parser.getgroup("terminal reporting")
-@@ -68,7 +80,7 @@ class LogXML(object):
-         logfile = os.path.expanduser(os.path.expandvars(logfile))
-         self.logfile = os.path.normpath(logfile)
-         self.prefix = prefix
--        self.test_logs = []
-+        self.tests = []
-         self.passed = self.skipped = 0
-         self.failed = self.errors = 0
- 
-@@ -82,89 +94,67 @@ class LogXML(object):
-         if self.prefix:
-             classnames.insert(0, self.prefix)
-         d['classname'] = ".".join(classnames)
--        d['name'] = py.xml.escape(names[-1])
--        attrs = ['%s="%s"' % item for item in sorted(d.items())]
--        self.test_logs.append("\n<testcase %s>" % " ".join(attrs))
-+        d['name'] = names[-1]
-+        self.tests.append(Junit.testcase(**d))
- 
--    def _closetestcase(self):
--        self.test_logs.append("</testcase>")
--
--    def appendlog(self, fmt, *args):
--        def repl(matchobj):
--            i = ord(matchobj.group())
--            if i <= 0xFF:
--                return unicode('#x%02X') % i
--            else:
--                return unicode('#x%04X') % i
--        args = tuple([illegal_xml_re.sub(repl, py.xml.escape(arg))
--                      for arg in args])
--        self.test_logs.append(fmt % args)
-+    def append(self, obj):
-+        self.tests[-1].append(obj)
- 
-     def append_pass(self, report):
-         self.passed += 1
--        self._opentestcase(report)
--        self._closetestcase()
- 
-     def append_failure(self, report):
--        self._opentestcase(report)
-         #msg = str(report.longrepr.reprtraceback.extraline)
-         if "xfail" in report.keywords:
--            self.appendlog(
--                '<skipped message="xfail-marked test passes unexpectedly"/>')
-+            self.append(
-+                Junit.skipped(message="xfail-marked test passes unexpectedly"))
-             self.skipped += 1
-         else:
-             sec = dict(report.sections)
--            self.appendlog('<failure message="test failure">%s</failure>',
--                report.longrepr)
-+            fail = Junit.failure(message="test failure")
-+            fail.append(str(report.longrepr))
-+            self.append(fail)
-             for name in ('out', 'err'):
-                 content = sec.get("Captured std%s" % name)
-                 if content:
--                    self.appendlog(
--                        "<system-%s>%%s</system-%s>" % (name, name), content)
-+                    tag = getattr(Junit, 'system-'+name)
-+                    self.append(tag(bin_xml_escape(content)))
-             self.failed += 1
--        self._closetestcase()
- 
-     def append_collect_failure(self, report):
--        self._opentestcase(report)
-         #msg = str(report.longrepr.reprtraceback.extraline)
--        self.appendlog('<failure message="collection failure">%s</failure>',
--            report.longrepr)
--        self._closetestcase()
-+        self.append(Junit.failure(str(report.longrepr),
-+                                  message="collection failure"))
-         self.errors += 1
- 
-     def append_collect_skipped(self, report):
--        self._opentestcase(report)
-         #msg = str(report.longrepr.reprtraceback.extraline)
--        self.appendlog('<skipped message="collection skipped">%s</skipped>',
--            report.longrepr)
--        self._closetestcase()
-+        self.append(Junit.skipped(str(report.longrepr),
-+                                  message="collection skipped"))
-         self.skipped += 1
- 
-     def append_error(self, report):
--        self._opentestcase(report)
--        self.appendlog('<error message="test setup failure">%s</error>',
--            report.longrepr)
--        self._closetestcase()
-+        self.append(Junit.error(str(report.longrepr),
-+                                message="test setup failure"))
-         self.errors += 1
- 
-     def append_skipped(self, report):
--        self._opentestcase(report)
-         if "xfail" in report.keywords:
--            self.appendlog(
--                '<skipped message="expected test failure">%s</skipped>',
--                report.keywords['xfail'])
-+            self.append(Junit.skipped(str(report.keywords['xfail']),
-+                                      message="expected test failure"))
-         else:
-             filename, lineno, skipreason = report.longrepr
-             if skipreason.startswith("Skipped: "):
-                 skipreason = skipreason[9:]
--            self.appendlog('<skipped type="pytest.skip" '
--                           'message="%s">%s</skipped>',
--                skipreason, "%s:%s: %s" % report.longrepr,
--                )
--        self._closetestcase()
-+            self.append(
-+                Junit.skipped("%s:%s: %s" % report.longrepr,
-+                              type="pytest.skip",
-+                              message=skipreason
-+                ))
-         self.skipped += 1
- 
-     def pytest_runtest_logreport(self, report):
-+        self._opentestcase(report)
-         if report.passed:
-             if report.when == "call": # ignore setup/teardown
-                 self.append_pass(report)
-@@ -178,6 +168,7 @@ class LogXML(object):
- 
-     def pytest_collectreport(self, report):
-         if not report.passed:
-+            self._opentestcase(report)
-             if report.failed:
-                 self.append_collect_failure(report)
-             else:
-@@ -186,10 +177,11 @@ class LogXML(object):
-     def pytest_internalerror(self, excrepr):
-         self.errors += 1
-         data = py.xml.escape(excrepr)
--        self.test_logs.append(
--            '\n<testcase classname="pytest" name="internal">'
--            '    <error message="internal error">'
--            '%s</error></testcase>' % data)
-+        self.tests.append(
-+            Junit.testcase(
-+                    Junit.error(data, message="internal error"),
-+                    classname="pytest",
-+                    name="internal"))
- 
-     def pytest_sessionstart(self, session):
-         self.suite_start_time = time.time()
-@@ -203,17 +195,17 @@ class LogXML(object):
-         suite_stop_time = time.time()
-         suite_time_delta = suite_stop_time - self.suite_start_time
-         numtests = self.passed + self.failed
-+
-         logfile.write('<?xml version="1.0" encoding="utf-8"?>')
--        logfile.write('<testsuite ')
--        logfile.write('name="" ')
--        logfile.write('errors="%i" ' % self.errors)
--        logfile.write('failures="%i" ' % self.failed)
--        logfile.write('skips="%i" ' % self.skipped)
--        logfile.write('tests="%i" ' % numtests)
--        logfile.write('time="%.3f"' % suite_time_delta)
--        logfile.write(' >')
--        logfile.writelines(self.test_logs)
--        logfile.write('</testsuite>')
-+        logfile.write(Junit.testsuite(
-+            self.tests,
-+            name="",
-+            errors=self.errors,
-+            failures=self.failed,
-+            skips=self.skipped,
-+            tests=numtests,
-+            time="%.3f" % suite_time_delta,
-+        ).unicode(indent=0))
-         logfile.close()
- 
-     def pytest_terminal_summary(self, terminalreporter):

File listchcain

-# HG changeset patch
-# Parent fa35a4fd9a6cd55b3bf832a62b65e6e007c088ae
-simplify the loop in Node.listchain
-
-diff --git a/_pytest/main.py b/_pytest/main.py
---- a/_pytest/main.py
-+++ b/_pytest/main.py
-@@ -229,13 +229,13 @@ class Node(object):
-     def listchain(self):
-         """ return list of all parent collectors up to self,
-             starting from root of collection tree. """
--        l = [self]
--        while 1:
--            x = l[0]
--            if x.parent is not None: # and x.parent.parent is not None:
--                l.insert(0, x.parent)
--            else:
--                return l
-+        l = []
-+        item = self
-+        while item is not None:
-+            l.append(item)
-+            item = item.parent
-+        l.reverse()
-+        return l
- 
-     def listnames(self):
-         return [x.name for x in self.listchain()]
-listchcain
-junitxml-pyxml
-regendoc-pytesthighlight
-unittest-skip-property
+regendoc-pytesthighlight #+doc
 fnmatch-python-test-names

File unittest-skip-property

-# HG changeset patch
-# Parent 7290ec4e3367d3d241e34d355f4a53b507f6108f
-take the skip property of unittest cases and functions into account
-
-diff --git a/CHANGELOG b/CHANGELOG
---- a/CHANGELOG
-+++ b/CHANGELOG
-@@ -29,6 +29,7 @@ Changes between 2.1.3 and 2.2.0
- - fix issue83: link to generated funcarg list
- - fix issue74: pyarg module names are now checked against imp.find_module false positives
- - fix compatibility with twisted/trial-11.1.0 use cases
-+- add support for skip properties on unittest classes and functions
- 
- Changes between 2.1.2 and 2.1.3
- ----------------------------------------
-diff --git a/_pytest/unittest.py b/_pytest/unittest.py
---- a/_pytest/unittest.py
-+++ b/_pytest/unittest.py
-@@ -46,6 +46,10 @@ class TestCaseFunction(pytest.Function):
-     def setup(self):
-         self._testcase = self.parent.obj(self.name)
-         self._obj = getattr(self._testcase, self.name)
-+        if hasattr(self._testcase, 'skip'):
-+            pytest.skip(self._testcase.skip)
-+        if hasattr(self._obj, 'skip'):
-+            pytest.skip(self._obj.skip)
-         if hasattr(self._testcase, 'setup_method'):
-             self._testcase.setup_method(self._obj)
- 
-diff --git a/testing/test_unittest.py b/testing/test_unittest.py
---- a/testing/test_unittest.py
-+++ b/testing/test_unittest.py
-@@ -232,6 +232,29 @@ def test_module_level_pytestmark(testdir
-     reprec.assertoutcome(skipped=1)
- 
- 
-+def test_testcase_skip_property(testdir):
-+    testpath = testdir.makepyfile("""
-+        import unittest
-+        class MyTestCase(unittest.TestCase):
-+            skip = 'dont run'
-+            def test_func(self):
-+                pass
-+        """)
-+    reprec = testdir.inline_run(testpath, "-s")
-+    reprec.assertoutcome(skipped=1)
-+
-+def test_testfunction_skip_property(testdir):
-+    testpath = testdir.makepyfile("""
-+        import unittest
-+        class MyTestCase(unittest.TestCase):
-+            def test_func(self):
-+                pass
-+            test_func.skip = 'dont run'
-+        """)
-+    reprec = testdir.inline_run(testpath, "-s")
-+    reprec.assertoutcome(skipped=1)
-+
-+
- class TestTrialUnittest:
-     def setup_class(cls):
-         pytest.importorskip("twisted.trial.unittest")