[Checkins] SVN: z3c.testsetup/trunk/src/z3c/testsetup/tests/ Add tests for setups in __init__ modules.

Uli Fouquet uli at gnufix.de
Wed Jul 23 19:39:50 EDT 2008


Log message for revision 88775:
  Add tests for setups in __init__ modules.

Changed:
  A   z3c.testsetup/trunk/src/z3c/testsetup/tests/cave/tests/
  A   z3c.testsetup/trunk/src/z3c/testsetup/tests/cave/tests/__init__.py
  A   z3c.testsetup/trunk/src/z3c/testsetup/tests/setupininit.txt
  U   z3c.testsetup/trunk/src/z3c/testsetup/tests/test_testsetup.py

-=-
Added: z3c.testsetup/trunk/src/z3c/testsetup/tests/cave/tests/__init__.py
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/tests/cave/tests/__init__.py	                        (rev 0)
+++ z3c.testsetup/trunk/src/z3c/testsetup/tests/cave/tests/__init__.py	2008-07-23 23:39:50 UTC (rev 88775)
@@ -0,0 +1,6 @@
+# this is a package that contains a testsetup.
+#
+# To let it be found by the testrunner, you must call the testrunner
+# with the approriate options set.
+import z3c.testsetup
+test_suite = z3c.testsetup.register_all_tests('z3c.testsetup.tests.cave')

Added: z3c.testsetup/trunk/src/z3c/testsetup/tests/setupininit.txt
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/tests/setupininit.txt	                        (rev 0)
+++ z3c.testsetup/trunk/src/z3c/testsetup/tests/setupininit.txt	2008-07-23 23:39:50 UTC (rev 88775)
@@ -0,0 +1,36 @@
+Setting up tests in packages __init__.py
+----------------------------------------
+
+We can also setup tests in packages' __init__ modules. We defined such
+a test setup in the cave package::
+
+    >>> import os
+    >>> cavepath = os.path.join(os.path.dirname(__file__), 'cave')
+
+The setup looks like this::
+
+    >>> setupfile = os.path.join(cavepath, 'tests', '__init__.py')
+    >>> print open(setupfile).read()
+    # this is a package that contains a testsetup.
+    #
+    # To let it be found by the testrunner, you must call the testrunner
+    # with the approriate options set.
+    import z3c.testsetup
+    test_suite = z3c.testsetup.register_all_tests('z3c.testsetup.tests.cave')
+
+Now we run this test, requiring `__init__` as the test-file-pattern
+for the testrunner::
+
+    >>> import sys
+    >>> defaults = [
+    ...     '--path', cavepath,
+    ...     '--tests-pattern', '^tests$',
+    ...     '--test-file-pattern', '__init__',
+    ...     ]
+    >>> sys.argv = 'test '.split()
+    >>> from zope.testing import testrunner
+    >>> testrunner.run(defaults)
+    Running unit tests:
+      Ran 2 tests with 0 failures and 0 errors in ... seconds.
+    False
+

Modified: z3c.testsetup/trunk/src/z3c/testsetup/tests/test_testsetup.py
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/tests/test_testsetup.py	2008-07-23 23:35:31 UTC (rev 88774)
+++ z3c.testsetup/trunk/src/z3c/testsetup/tests/test_testsetup.py	2008-07-23 23:39:50 UTC (rev 88775)
@@ -10,7 +10,9 @@
 TESTFILES = ['basicsetup.txt',
              os.path.join('functional', 'functionaldoctestsetup.txt'),
              'pythontestsetup.txt', 'unitdoctestsetup.txt', 'util.txt',
-             'unittestsetup.txt']
+             'unittestsetup.txt',
+             os.path.join('tests', 'setupininit.txt'),
+             ]
 
 def pnorm(path):
     """Normalization of paths to use forward slashes. This is needed



More information about the Checkins mailing list