[Checkins] SVN: zope.testrunner/trunk/ Testing with setup.py.

Lennart Regebro regebro at gmail.com
Wed Apr 28 15:17:32 EDT 2010


Log message for revision 111556:
  Testing with setup.py.
  

Changed:
  U   zope.testrunner/trunk/DEVELOPING.txt
  U   zope.testrunner/trunk/setup.py

-=-
Modified: zope.testrunner/trunk/DEVELOPING.txt
===================================================================
--- zope.testrunner/trunk/DEVELOPING.txt	2010-04-28 17:27:36 UTC (rev 111555)
+++ zope.testrunner/trunk/DEVELOPING.txt	2010-04-28 19:17:32 UTC (rev 111556)
@@ -17,35 +17,29 @@
     Tearing down left over layers:
       Tear down zope.testrunner.layer.UnitTests in 0.000 seconds.    
     
-However, you may run the tests without buildout, by installing zope.testrunner,
-and using the zope-testrunner script that the instalation creates. To make
-sure you don't install broken development versions in your Python installation,
-it's best to do this in an isolated environment, such as set up with 
-Ian Bickings 'Virtualenv' tool. See http://pypi.python.org/pypi/virtualenv
-for instructions on how to install virtualenv::
+However, you may run the tests without buildout as well, as the setup.py has
+a custom test command that will run the tests:
 
-    # virtualenv .
-    New python executable in ./bin/python
-    Installing setuptools............done.
-    
-    # ./bin/python setup.py -q install
-    
-    # ./bin/zope-testrunner --test-path src/
+    # python setup.py test
+    running test
+    running egg_info
+    writing requirements to src/zope.testrunner.egg-info/requires.txt
+    writing src/zope.testrunner.egg-info/PKG-INFO
+    writing namespace_packages to src/zope.testrunner.egg-info/namespace_packages.txt
+    writing top-level names to src/zope.testrunner.egg-info/top_level.txt
+    writing dependency_links to src/zope.testrunner.egg-info/dependency_links.txt
+    writing entry points to src/zope.testrunner.egg-info/entry_points.txt
+    reading manifest template 'MANIFEST.in'
+    warning: no files found matching 'sampletests' under directory 'src'
+    writing manifest file 'src/zope.testrunner.egg-info/SOURCES.txt'
+    running build_ext
     Running zope.testrunner.layer.UnitTests tests:
       Set up zope.testrunner.layer.UnitTests in 0.000 seconds.
-      Ran 27 tests with 0 failures and 0 errors in 17.384 seconds.
+      Ran 27 tests with 0 failures and 0 errors in 17.600 seconds.
     Tearing down left over layers:
       Tear down zope.testrunner.layer.UnitTests in 0.000 seconds.
 
-The drawback with the non-buildout setup is that you need to re-run the install
-before every testrun, to make sure the installed code is updated::
+Which one you prefer is much a matter of taste. At the moment of writing
+buildout does not support Python 3, and therefore you must use this way
+of testing under Python 3.
 
-    # ./bin/python setup.py -q install    
-    # ./bin/zope-testrunner --test-path src/
-    
-If you run Python 3, you need to run the tests against the converted source in
-the build directory::
-
-    # ./bin/python3 setup.py -q install    
-    # ./bin/zope-testrunner --test-path build/lib/
-    

Modified: zope.testrunner/trunk/setup.py
===================================================================
--- zope.testrunner/trunk/setup.py	2010-04-28 17:27:36 UTC (rev 111555)
+++ zope.testrunner/trunk/setup.py	2010-04-28 19:17:32 UTC (rev 111556)
@@ -22,9 +22,92 @@
 """
 
 import os
-
+import sys
 from setuptools import setup
 
+if sys.version_info >= (3,):
+    extra = dict(use_2to3 = True,
+                 setup_requires = ['zope.fixers'],
+                 use_2to3_fixers = ['zope.fixers'],
+                 convert_2to3_doctests = [
+                     'src/zope/testing/doctests.txt',
+                     'src/zope/testing/formparser.txt',
+                     'src/zope/testing/module.txt',
+                     'src/zope/testing/setupstack.txt',
+                     'src/zope/testing/testrunner/testrunner-arguments.txt',
+                     'src/zope/testing/testrunner/testrunner-coverage-win32.txt',
+                     'src/zope/testing/testrunner/testrunner-coverage.txt',
+                     'src/zope/testing/testrunner/testrunner-debugging-layer-setup.test',
+                     'src/zope/testing/testrunner/testrunner-debugging.txt',
+                     'src/zope/testing/testrunner/testrunner-discovery',
+                     'src/zope/testing/testrunner/testrunner-edge-cases.txt',
+                     'src/zope/testing/testrunner/testrunner-errors.txt',
+                     'src/zope/testing/testrunner/testrunner-gc.txt',
+                     'src/zope/testing/testrunner/testrunner-knit.txt',
+                     'src/zope/testing/testrunner/testrunner-layers-api.txt',
+                     'src/zope/testing/testrunner/testrunner-layers-buff.txt',
+                     'src/zope/testing/testrunner/testrunner-layers-ntd.txt',
+                     'src/zope/testing/testrunner/testrunner-layers.txt',
+                     'src/zope/testing/testrunner/testrunner-leaks-err.txt',
+                     'src/zope/testing/testrunner/testrunner-leaks.txt',
+                     'src/zope/testing/testrunner/testrunner-profiling-cprofiler.txt',
+                     'src/zope/testing/testrunner/testrunner-profiling.txt',
+                     'src/zope/testing/testrunner/testrunner-progress.txt',
+                     'src/zope/testing/testrunner/testrunner-repeat.txt',
+                     'src/zope/testing/testrunner/testrunner-simple.txt',
+                     'src/zope/testing/testrunner/testrunner-tb-format.txt',
+                     'src/zope/testing/testrunner/testrunner-test-selection.txt',
+                     'src/zope/testing/testrunner/testrunner-verbose.txt',
+                     'src/zope/testing/testrunner/testrunner-wo-source.txt',
+                     'src/zope/testing/testrunner/testrunner.txt',
+                     'src/zope/testing/testrunner/testrunner-ex/sampletests.txt',
+                     'src/zope/testing/testrunner/testrunner-ex/sampletestsl.txt',
+                     'src/zope/testing/testrunner/testrunner-ex/unicode.txt',
+                     ],
+                 dependency_links = ['.'],
+                 )
+else:
+    extra = {}
+
+from setuptools.command.test import test
+
+class custom_test(test):
+    # The zope.testing tests MUST be run using it's own testrunner. This is
+    # because it's subprocess testing will call the script it was run with. We
+    # therefore create a script to run the testrunner, and call that.
+    def run(self):
+        if self.distribution.install_requires:
+            self.distribution.fetch_build_eggs(self.distribution.install_requires)
+        if self.distribution.tests_require:
+            self.distribution.fetch_build_eggs(self.distribution.tests_require)
+        self.with_project_on_sys_path(self.run_tests)
+
+    def run_tests(self):
+        template = """
+import sys
+sys.path = %s
+
+import os
+os.chdir('%s')
+
+import zope.testrunner
+if __name__ == '__main__':
+    zope.testrunner.run([
+        '--test-path', '%s',
+        ])
+        """
+        import tempfile
+        fd, filename = tempfile.mkstemp(prefix='temprunner', text=True)
+        scriptfile = open(filename, 'w')
+        script = template % (sys.path, os.path.abspath(os.curdir), os.path.abspath('src'))
+        scriptfile.write(script)
+        scriptfile.close()
+ 
+        import subprocess
+        process = subprocess.Popen([sys.executable, filename])
+        process.wait()
+        os.unlink(filename)
+
 chapters = '\n'.join([
     open(os.path.join('src', 'zope', 'testrunner', name)).read()
     for name in (
@@ -95,5 +178,6 @@
             ['zope-testrunner = zope.testrunner:run',]},
     include_package_data = True,
     zip_safe = False,
-    dependency_links = ['.'], # Only until the release of zope.testing 4.0.0
+    cmdclass = {'test': custom_test},
+    **extra
 )



More information about the checkins mailing list