[Checkins] SVN: z3c.testsetup/trunk/ - Python unittest modules with an import error now result in a visible

Reinout van Rees reinout at vanrees.org
Thu Nov 19 05:00:39 EST 2009


Log message for revision 105866:
  - Python unittest modules with an import error now result in a visible
    warning.  Previously, such problems would be hidden.  Also the python
    testrunner could not report them as broken as we did not pass those test
    files to the testrunner.
  
  - Fixed regex for detecting the old ":test-layer: python" marker: it did not
    work when prefixed with restructuredtext's ".." comment marker.
  
  

Changed:
  U   z3c.testsetup/trunk/CHANGES.txt
  U   z3c.testsetup/trunk/src/z3c/testsetup/pythontestsetup.txt
  U   z3c.testsetup/trunk/src/z3c/testsetup/testing.py
  A   z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/
  A   z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/__init__.py
  A   z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/broken_test_mod.py
  A   z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/broken_test_mod2.py
  U   z3c.testsetup/trunk/src/z3c/testsetup/unittestsetup.txt

-=-
Modified: z3c.testsetup/trunk/CHANGES.txt
===================================================================
--- z3c.testsetup/trunk/CHANGES.txt	2009-11-19 09:53:48 UTC (rev 105865)
+++ z3c.testsetup/trunk/CHANGES.txt	2009-11-19 10:00:39 UTC (rev 105866)
@@ -4,9 +4,15 @@
 0.6 (unreleased)
 ================
 
-- Nothing changed yet.
+- Python unittest modules with an import error now result in a visible
+  warning.  Previously, such problems would be hidden.  Also the python
+  testrunner could not report them as broken as we did not pass those test
+  files to the testrunner.
 
+- Fixed regex for detecting the old ":test-layer: python" marker: it did not
+  work when prefixed with restructuredtext's ".." comment marker.
 
+
 0.5.1 (2009-10-22)
 ==================
 

Modified: z3c.testsetup/trunk/src/z3c/testsetup/pythontestsetup.txt
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/pythontestsetup.txt	2009-11-19 09:53:48 UTC (rev 105865)
+++ z3c.testsetup/trunk/src/z3c/testsetup/pythontestsetup.txt	2009-11-19 10:00:39 UTC (rev 105866)
@@ -172,11 +172,11 @@
 
     `:unittest:`
 
-This marker is determined by a list of regular expressions, which is
-also available as an object attribute::
+The old ":TestLayer: python" marker is determined by a list of regular
+expressions, which is also available as an object attribute::
 
     >>> setup.regexp_list
-    ['^\\s*:(T|t)est-(L|l)ayer:\\s*(python)\\s*']
+    ['^\\.{0,2}\\s*:(T|t)est-(L|l)ayer:\\s*(python)\\s*']
 
 This is the default value of Python unit test setups.
 

Modified: z3c.testsetup/trunk/src/z3c/testsetup/testing.py
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/testing.py	2009-11-19 09:53:48 UTC (rev 105865)
+++ z3c.testsetup/trunk/src/z3c/testsetup/testing.py	2009-11-19 10:00:39 UTC (rev 105866)
@@ -37,9 +37,9 @@
     """
 
     regexp_list = [
-        '^\s*:(T|t)est-(L|l)ayer:\s*(python)\s*',
+        r'^\.{0,2}\s*:(T|t)est-(L|l)ayer:\s*(python)\s*',
         ]
-    
+
     def __init__(self, package, pfilter_func=None, regexp_list=None):
         BasicTestSetup.__init__(self, package, regexp_list=regexp_list)
         self.pfilter_func = pfilter_func or self.isTestModule
@@ -73,15 +73,17 @@
         # Do not even try to load modules, that have no marker string.
         if not self.fileContains(
             module_info.path, self.regexp_list):
+            # No ":test-layer: python" marker, so check for :unittest:.
             if get_marker_from_file('unittest', module_info.path) is None:
+                # Neither the old nor the new marker: this is no test module.
                 return False
-        module = None        
+        module = None
         try:
             module = module_info.getModule()
         except ImportError:
-            # Broken modules cannot provide executable tests.
-            # We might throw out a warning here...
-            return False
+            # Broken module that is probably a test.  We absolutely have to
+            # warn about this!
+            print "Import error in", module_info.path
         docstr = getattr(module, '__doc__', '')
         if not self.docstrContains(docstr, self.regexp_list):
             return False
@@ -101,8 +103,8 @@
             module = submod_info.getModule()
             result.append(module)
         return result
-        
 
+
     def getTestSuite(self):
         modules = self.getModules(package=self.package)
         suite = unittest.TestSuite()

Added: z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/__init__.py
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/__init__.py	                        (rev 0)
+++ z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/__init__.py	2009-11-19 10:00:39 UTC (rev 105866)
@@ -0,0 +1 @@
+#package


Property changes on: z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/__init__.py
___________________________________________________________________
Added: svn:eol-style
   + native

Added: z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/broken_test_mod.py
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/broken_test_mod.py	                        (rev 0)
+++ z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/broken_test_mod.py	2009-11-19 10:00:39 UTC (rev 105866)
@@ -0,0 +1,11 @@
+"""
+
+.. :unittest:
+
+This module is broken *and* it is marked as a test module
+
+A warning should be printed
+
+"""
+
+import non_existing_package


Property changes on: z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/broken_test_mod.py
___________________________________________________________________
Added: svn:eol-style
   + native

Added: z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/broken_test_mod2.py
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/broken_test_mod2.py	                        (rev 0)
+++ z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/broken_test_mod2.py	2009-11-19 10:00:39 UTC (rev 105866)
@@ -0,0 +1,11 @@
+"""
+
+.. :Test-Layer: python
+
+This module is broken *and* it is marked as a test module (though in the old way).
+
+A warning should be printed
+
+"""
+
+import non_existing_package


Property changes on: z3c.testsetup/trunk/src/z3c/testsetup/tests/importerrorcave/broken_test_mod2.py
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: z3c.testsetup/trunk/src/z3c/testsetup/unittestsetup.txt
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/unittestsetup.txt	2009-11-19 09:53:48 UTC (rev 105865)
+++ z3c.testsetup/trunk/src/z3c/testsetup/unittestsetup.txt	2009-11-19 10:00:39 UTC (rev 105866)
@@ -43,22 +43,22 @@
 
 We want to register the tests contained in the local ``cave``
 package. This has to be imported first, because we need the package as
-a parameter for the testseupt constructor::
+a parameter for the testsetup constructor::
 
-   >>> from z3c.testsetup.tests import cave
+    >>> from z3c.testsetup.tests import cave
 
 Using the ``UnitTestSetup`` then is easy::
 
-   >>> from z3c.testsetup import UnitTestSetup
-   >>> setup = UnitTestSetup(cave)
-   >>> setup
-   <z3c.testsetup.testing.UnitTestSetup object at 0x...>   
+    >>> from z3c.testsetup import UnitTestSetup
+    >>> setup = UnitTestSetup(cave)
+    >>> setup
+    <z3c.testsetup.testing.UnitTestSetup object at 0x...>   
 
 This setup is ready for use::
 
-   >>> suite = setup.getTestSuite()
-   >>> suite
-   <unittest.TestSuite tests=[...]>
+    >>> suite = setup.getTestSuite()
+    >>> suite
+    <unittest.TestSuite tests=[...]>
 
 To sum it up, writing a test setup for a zope 3 project now can be that
 short::
@@ -187,5 +187,24 @@
 test setup class and overwrite ``isTestModule()``.
 
 
+Import errors
+-------------
 
+Python unittest files with an import error should not ever fail silently.  Due
+to our internal handling, z3c.testsetup cannot pass the broken modules to the
+actual testrunner (which would report them just fine as broken).  Instead, we
+have to print a warning ourselves.
+
+    >>> from z3c.testsetup.tests import importerrorcave
+    >>> setup = UnitTestSetup(importerrorcave)
+    >>> setup
+    <z3c.testsetup.testing.UnitTestSetup object at 0x...>   
+    >>> setup.getModules()
+    Import error in .../importerrorcave/broken_test_mod.py
+    Import error in .../importerrorcave/broken_test_mod2.py
+    []
+
+Note that this visible warning was added in z3c.testsetup 0.6 and higher,
+tests import error failures were effectively hidden in older versions.
+
 """



More information about the checkins mailing list