[py-svn] r62207 - in py/branch/pytestplugin/py/test: . plugin testing

hpk at codespeak.net hpk at codespeak.net
Fri Feb 27 10:42:35 CET 2009


Author: hpk
Date: Fri Feb 27 10:42:35 2009
New Revision: 62207

Added:
   py/branch/pytestplugin/py/test/plugin/pytest_default.py
Modified:
   py/branch/pytestplugin/py/test/collect.py
   py/branch/pytestplugin/py/test/config.py
   py/branch/pytestplugin/py/test/defaultconftest.py
   py/branch/pytestplugin/py/test/parseopt.py
   py/branch/pytestplugin/py/test/testing/test_parseopt.py
Log:
shifting pytest defaults to a new DefaultPlugin



Modified: py/branch/pytestplugin/py/test/collect.py
==============================================================================
--- py/branch/pytestplugin/py/test/collect.py	(original)
+++ py/branch/pytestplugin/py/test/collect.py	Fri Feb 27 10:42:35 2009
@@ -480,7 +480,7 @@
         return l
 
     def consider_dir(self, path, usefilters=None):
-        if usefilters is None:
+        if usefilters is not None:
             APIWARN("0.99", "usefilters argument not needed")
         if not self.recfilter(path):
             # check if cmdline specified this dir or a subdir

Modified: py/branch/pytestplugin/py/test/config.py
==============================================================================
--- py/branch/pytestplugin/py/test/config.py	(original)
+++ py/branch/pytestplugin/py/test/config.py	Fri Feb 27 10:42:35 2009
@@ -2,7 +2,6 @@
 
 import py
 from conftesthandle import Conftest
-from py.__.test.defaultconftest import adddefaultoptions
 
 from py.__.test import parseopt
 from py.__.misc.warn import APIWARN
@@ -55,7 +54,6 @@
         assert not self._initialized, (
                 "can only parse cmdline args at most once per Config object")
         self._initialized = True
-        adddefaultoptions(self)
         self._conftest.setinitial(args) 
         self.pytestplugins.consider_env()
         self.pytestplugins.do_addoption(self._parser)

Modified: py/branch/pytestplugin/py/test/defaultconftest.py
==============================================================================
--- py/branch/pytestplugin/py/test/defaultconftest.py	(original)
+++ py/branch/pytestplugin/py/test/defaultconftest.py	Fri Feb 27 10:42:35 2009
@@ -10,10 +10,8 @@
 
 conf_iocapture = "fd" # overridable from conftest.py 
 
-# XXX resultlog should go, but pypy's nightrun depends on this
-# default, need to change the pypy buildbot master configuration 
-
-pytest_plugins = "terminal xfail tmpdir resultlog monkeypatch".split()
+# XXX resultlog should go, pypy's nightrun depends on it
+pytest_plugins = "default terminal xfail tmpdir resultlog monkeypatch".split()
 
 # ===================================================
 # Distributed testing specific options 
@@ -21,7 +19,7 @@
 #dist_hosts: needs to be provided by user
 #dist_rsync_roots: might be provided by user, if not present or None,
 #                  whole pkgdir will be rsynced
-# XXX deprecated dist_remotepython = None
+
 dist_taskspernode = 15
 dist_boxed = False
 if hasattr(py.std.os, 'nice'):
@@ -30,85 +28,3 @@
     dist_nicelevel = 0
 dist_rsync_ignore = []
 
-# ===================================================
-
-class ConftestPlugin:        
-    def pytest_collect_file(self, path, parent):
-        ext = path.ext 
-        pb = path.purebasename
-        if pb.startswith("test_") or pb.endswith("_test") or \
-           path in parent._config.args:
-            if ext == ".py":
-                return parent.Module(path, parent=parent) 
-
-def adddefaultoptions(config):
-    Option = config.Option 
-    group = config._parser.addgroup("general", "general options")
-    group._addoption('-v', '--verbose', action="count", 
-               dest="verbose", default=0, help="increase verbosity."),
-    group._addoption('-x', '--exitfirst',
-               action="store_true", dest="exitfirst", default=False,
-               help="exit instantly on first error or failed test."),
-    group._addoption('-s', '--nocapture',
-               action="store_true", dest="nocapture", default=False,
-               help="disable catching of sys.stdout/stderr output."),
-    group._addoption('-k',
-               action="store", dest="keyword", default='',
-               help="only run test items matching the given "
-                    "keyword expression."),
-    group._addoption('-l', '--showlocals',
-               action="store_true", dest="showlocals", default=False,
-               help="show locals in tracebacks (disabled by default)."),
-    group._addoption('--showskipsummary',
-               action="store_true", dest="showskipsummary", default=False,
-               help="always show summary of skipped tests"), 
-    group._addoption('', '--pdb',
-               action="store_true", dest="usepdb", default=False,
-               help="start pdb (the Python debugger) on errors."),
-    group._addoption('', '--tb',
-               action="store", dest="tbstyle", default='long',
-               type="choice", choices=['long', 'short', 'no'],
-               help="traceback verboseness (long/short/no)."),
-    group._addoption('', '--fulltrace',
-               action="store_true", dest="fulltrace", default=False,
-               help="don't cut any tracebacks (default is to cut)."),
-    group._addoption('', '--nomagic',
-               action="store_true", dest="nomagic", default=False,
-               help="refrain from using magic as much as possible."),
-    group._addoption('', '--traceconfig',
-               action="store_true", dest="traceconfig", default=False,
-               help="trace considerations of conftest.py files."),
-    group._addoption('-f', '--looponfailing',
-               action="store_true", dest="looponfailing", default=False,
-               help="loop on failing test set."),
-    group._addoption('', '--exec',
-               action="store", dest="executable", default=None,
-               help="python executable to run the tests with."),
-    group._addoption('-n', '--numprocesses', dest="numprocesses", default=0, 
-               action="store", type="int", 
-               help="number of local test processes."),
-    group._addoption('', '--debug',
-               action="store_true", dest="debug", default=False,
-               help="turn on debugging information."),
-
-    group = config._parser.addgroup("experimental", "experimental options")
-    group._addoption('-d', '--dist',
-               action="store_true", dest="dist", default=False,
-               help="ad-hoc distribute tests across machines (requires conftest settings)"), 
-    group._addoption('-w', '--startserver',
-               action="store_true", dest="startserver", default=False,
-               help="starts local web server for displaying test progress.", 
-               ),
-    group._addoption('-r', '--runbrowser',
-               action="store_true", dest="runbrowser", default=False,
-               help="run browser (implies --startserver)."
-               ),
-    group._addoption('', '--boxed',
-               action="store_true", dest="boxed", default=False,
-               help="box each test run in a separate process"), 
-    group._addoption('', '--rest',
-               action='store_true', dest="restreport", default=False,
-               help="restructured text output reporting."),
-    group._addoption('', '--session',
-               action="store", dest="session", default=None,
-               help="lookup given sessioname in conftest.py files and use it."),

Modified: py/branch/pytestplugin/py/test/parseopt.py
==============================================================================
--- py/branch/pytestplugin/py/test/parseopt.py	(original)
+++ py/branch/pytestplugin/py/test/parseopt.py	Fri Feb 27 10:42:35 2009
@@ -55,7 +55,7 @@
                 optgroup = optparse.OptionGroup(optparser, group.name)
                 optgroup.add_options(group.options)
                 optparser.add_option_group(optgroup)
-        return optparser.parse_args(args)
+        return optparser.parse_args([str(x) for x in args])
 
     def parse_setoption(self, args, option):
         parsedoption, args = self.parse(args)

Added: py/branch/pytestplugin/py/test/plugin/pytest_default.py
==============================================================================
--- (empty file)
+++ py/branch/pytestplugin/py/test/plugin/pytest_default.py	Fri Feb 27 10:42:35 2009
@@ -0,0 +1,81 @@
+class DefaultPlugin:
+    """ Plugin implementing defaults and general options. """ 
+
+    def pytest_collect_file(self, path, parent):
+        ext = path.ext 
+        pb = path.purebasename
+        if pb.startswith("test_") or pb.endswith("_test") or \
+           path in parent._config.args:
+            if ext == ".py":
+                return parent.Module(path, parent=parent) 
+
+    def pytest_addoption(self, parser):
+        group = parser.addgroup("general", "general options")
+        group._addoption('-v', '--verbose', action="count", 
+                   dest="verbose", default=0, help="increase verbosity."),
+        group._addoption('-x', '--exitfirst',
+                   action="store_true", dest="exitfirst", default=False,
+                   help="exit instantly on first error or failed test."),
+        group._addoption('-s', '--nocapture',
+                   action="store_true", dest="nocapture", default=False,
+                   help="disable catching of sys.stdout/stderr output."),
+        group._addoption('-k',
+                   action="store", dest="keyword", default='',
+                   help="only run test items matching the given "
+                        "keyword expression."),
+        group._addoption('-l', '--showlocals',
+                   action="store_true", dest="showlocals", default=False,
+                   help="show locals in tracebacks (disabled by default)."),
+        group._addoption('--showskipsummary',
+                   action="store_true", dest="showskipsummary", default=False,
+                   help="always show summary of skipped tests"), 
+        group._addoption('', '--pdb',
+                   action="store_true", dest="usepdb", default=False,
+                   help="start pdb (the Python debugger) on errors."),
+        group._addoption('', '--tb',
+                   action="store", dest="tbstyle", default='long',
+                   type="choice", choices=['long', 'short', 'no'],
+                   help="traceback verboseness (long/short/no)."),
+        group._addoption('', '--fulltrace',
+                   action="store_true", dest="fulltrace", default=False,
+                   help="don't cut any tracebacks (default is to cut)."),
+        group._addoption('', '--nomagic',
+                   action="store_true", dest="nomagic", default=False,
+                   help="refrain from using magic as much as possible."),
+        group._addoption('', '--traceconfig',
+                   action="store_true", dest="traceconfig", default=False,
+                   help="trace considerations of conftest.py files."),
+        group._addoption('-f', '--looponfailing',
+                   action="store_true", dest="looponfailing", default=False,
+                   help="loop on failing test set."),
+        group._addoption('', '--exec',
+                   action="store", dest="executable", default=None,
+                   help="python executable to run the tests with."),
+        group._addoption('-n', '--numprocesses', dest="numprocesses", default=0, 
+                   action="store", type="int", 
+                   help="number of local test processes."),
+        group._addoption('', '--debug',
+                   action="store_true", dest="debug", default=False,
+                   help="turn on debugging information."),
+
+        group = parser.addgroup("experimental", "experimental options")
+        group._addoption('-d', '--dist',
+                   action="store_true", dest="dist", default=False,
+                   help="ad-hoc distribute tests across machines (requires conftest settings)"), 
+        group._addoption('-w', '--startserver',
+                   action="store_true", dest="startserver", default=False,
+                   help="starts local web server for displaying test progress.", 
+                   ),
+        group._addoption('-r', '--runbrowser',
+                   action="store_true", dest="runbrowser", default=False,
+                   help="run browser (implies --startserver)."
+                   ),
+        group._addoption('', '--boxed',
+                   action="store_true", dest="boxed", default=False,
+                   help="box each test run in a separate process"), 
+        group._addoption('', '--rest',
+                   action='store_true', dest="restreport", default=False,
+                   help="restructured text output reporting."),
+        group._addoption('', '--session',
+                   action="store", dest="session", default=None,
+                   help="lookup given sessioname in conftest.py files and use it."),

Modified: py/branch/pytestplugin/py/test/testing/test_parseopt.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_parseopt.py	(original)
+++ py/branch/pytestplugin/py/test/testing/test_parseopt.py	Fri Feb 27 10:42:35 2009
@@ -50,6 +50,11 @@
         assert option.hello == "world"
         assert not args
 
+    def test_parse(self):
+        parser = parseopt.Parser()
+        option, args = parser.parse([py.path.local()])
+        assert args[0] == py.path.local()
+
     def test_parse_will_set_default(self):
         parser = parseopt.Parser()
         parser.addoption("--hello", dest="hello", default="x", action="store")



More information about the pytest-commit mailing list