[py-svn] r62981 - in py/trunk/py/test: . dsession dsession/testing plugin testing

hpk at codespeak.net hpk at codespeak.net
Tue Mar 17 07:10:40 CET 2009


Author: hpk
Date: Tue Mar 17 07:10:40 2009
New Revision: 62981

Modified:
   py/trunk/py/test/config.py
   py/trunk/py/test/dsession/dsession.py
   py/trunk/py/test/dsession/hostmanage.py
   py/trunk/py/test/dsession/testing/test_dsession.py
   py/trunk/py/test/plugin/pytest_pytester.py
   py/trunk/py/test/testing/acceptance_test.py
   py/trunk/py/test/testing/test_config.py
Log:
allowing conftest to set default values for options


Modified: py/trunk/py/test/config.py
==============================================================================
--- py/trunk/py/test/config.py	(original)
+++ py/trunk/py/test/config.py	Tue Mar 17 07:10:40 2009
@@ -63,6 +63,12 @@
                 elif not opt.type and opt.action in ("store_true", "store_false"):
                     val = eval(val)
                 opt.default = val 
+            else:
+                name = "pytest_option_" + opt.dest
+                try:
+                    opt.default = self._conftest.rget(name)
+                except (ValueError, KeyError):
+                    pass
             if not hasattr(self.option, opt.dest):
                 setattr(self.option, opt.dest, opt.default)
 

Modified: py/trunk/py/test/dsession/dsession.py
==============================================================================
--- py/trunk/py/test/dsession/dsession.py	(original)
+++ py/trunk/py/test/dsession/dsession.py	Tue Mar 17 07:10:40 2009
@@ -60,16 +60,12 @@
         if config.option.numprocesses:
             return
         try:
-            config.getvalue('dist_hosts')
+            config.getvalue('hosts')
         except KeyError:
-            print "Don't know where to distribute tests to.  You may want"
-            print "to specify either a number of local processes to start"
-            print "with '--numprocesses=NUM' or specify 'dist_hosts' in a local"
-            print "conftest.py file, for example:"
-            print
-            print "  dist_hosts = ['localhost'] * 4 # for 3 processors"
-            print "  dist_hosts = ['you at remote.com', '...'] # for testing on ssh accounts"
-            print "   # with your remote ssh accounts"
+            print "Please specify hosts for distribution of tests:"
+            print "cmdline: --hosts=host1,host2,..."
+            print "conftest.py: pytest_option_hosts=['host1','host2',]"
+            print "environment: PYTEST_OPTION_HOSTS=host1,host2,host3"
             print 
             print "see also: http://codespeak.net/py/current/doc/test.html#automated-distributed-testing"
             raise SystemExit

Modified: py/trunk/py/test/dsession/hostmanage.py
==============================================================================
--- py/trunk/py/test/dsession/hostmanage.py	(original)
+++ py/trunk/py/test/dsession/hostmanage.py	Tue Mar 17 07:10:40 2009
@@ -6,7 +6,7 @@
 
 def getconfighosts(config):
     if config.option.numprocesses:
-        hosts = ['localhost'] * config.option.numprocesses
+        hosts = ['popen'] * config.option.numprocesses
     else:
         hosts = config.option.hosts
         if not hosts:

Modified: py/trunk/py/test/dsession/testing/test_dsession.py
==============================================================================
--- py/trunk/py/test/dsession/testing/test_dsession.py	(original)
+++ py/trunk/py/test/dsession/testing/test_dsession.py	Tue Mar 17 07:10:40 2009
@@ -300,17 +300,17 @@
         remaining = session.filteritems(items)
         assert remaining == []
         
-        evname, ev = evrec.events[-1]
-        assert evname == "deselected"
-        assert ev.items == items 
+        event = evrec.events[-1]
+        assert event.name == "deselected"
+        assert event.args[0].items == items 
 
         modcol._config.option.keyword = "test_fail"
         remaining = session.filteritems(items)
         assert remaining == [items[0]]
 
-        evname, ev = evrec.events[-1]
-        assert evname == "deselected"
-        assert ev.items == [items[1]]
+        event = evrec.events[-1]
+        assert event.name == "deselected"
+        assert event.args[0].items == [items[1]]
 
     def test_hostdown_shutdown_after_completion(self, testdir):
         item = testdir.getitem("def test_func(): pass")

Modified: py/trunk/py/test/plugin/pytest_pytester.py
==============================================================================
--- py/trunk/py/test/plugin/pytest_pytester.py	(original)
+++ py/trunk/py/test/plugin/pytest_pytester.py	Tue Mar 17 07:10:40 2009
@@ -236,6 +236,11 @@
     def runpytest(self, *args):
         return self.runpybin("py.test", *args)
 
+class Event:
+    def __init__(self, name, args, kwargs):
+        self.name = name
+        self.args = args
+        self.kwargs = kwargs
 
 class EventRecorder(object):
     def __init__(self, pyplugins, debug=False): # True):
@@ -249,26 +254,27 @@
             return
         if self.debug:
             print "[event: %s]: %s **%s" %(name, ", ".join(map(str, args)), kwargs,)
-        self.events.append((name,) + tuple(args))
+        self.events.append(Event(name, args, kwargs))
 
     def get(self, cls):
         l = []
-        for name, value in self.events:
+        for event in self.events:
+            value = event.args[0]
             if isinstance(value, cls):
                 l.append(value)
         return l 
 
     def getnamed(self, *names):
         l = []
-        for evname, event in self.events:
-            if evname in names:
-                l.append(event)
+        for event in self.events:
+            if event.name in names:
+                l.append(event.args[0])
         return l 
 
     def getfirstnamed(self, name):
-        for evname, event in self.events:
-            if evname == name:
-                return event
+        for event in self.events:
+            if event.name == name:
+                return event.args[0]
 
     def getfailures(self, names='itemtestreport collectionreport'):
         l = []

Modified: py/trunk/py/test/testing/acceptance_test.py
==============================================================================
--- py/trunk/py/test/testing/acceptance_test.py	(original)
+++ py/trunk/py/test/testing/acceptance_test.py	Tue Mar 17 07:10:40 2009
@@ -252,6 +252,31 @@
         ])
         assert result.ret == 1
 
+    def test_dist_testing_conftest_specified(self, testdir):
+        p1 = testdir.makepyfile("""
+                import py
+                def test_fail0():
+                    assert 0
+                def test_fail1():
+                    raise ValueError()
+                def test_ok():
+                    pass
+                def test_skip():
+                    py.test.skip("hello")
+            """, 
+        )
+        testdir.makeconftest("""
+            pytest_option_hosts='popen,popen,popen'
+        """)
+        result = testdir.runpytest(p1, '-d')
+        result.stdout.fnmatch_lines([
+            "HOSTUP: popen*Python*",
+            #"HOSTUP: localhost*Python*",
+            #"HOSTUP: localhost*Python*",
+            "*2 failed, 1 passed, 1 skipped*",
+        ])
+        assert result.ret == 1
+
     def test_dist_tests_with_crash(self, testdir):
         if not hasattr(py.std.os, 'kill'):
             py.test.skip("no os.kill")

Modified: py/trunk/py/test/testing/test_config.py
==============================================================================
--- py/trunk/py/test/testing/test_config.py	(original)
+++ py/trunk/py/test/testing/test_config.py	Tue Mar 17 07:10:40 2009
@@ -40,6 +40,12 @@
         group.addoption("--option4", action="store", type="int")
         assert group.options[3].default == ("NO", "DEFAULT")
 
+    def test_parser_addoption_default_conftest(self, testdir, monkeypatch):
+        import os
+        testdir.makeconftest("pytest_option_verbose=True")
+        config = testdir.parseconfig()
+        assert config.option.verbose 
+
     def test_config_cmdline_options_only_lowercase(self, testdir): 
         testdir.makepyfile(conftest="""
             import py



More information about the pytest-commit mailing list