[py-svn] r11855 - in py/dist/py/test: . testing
hpk at codespeak.net
hpk at codespeak.net
Tue May 3 15:02:43 CEST 2005
Author: hpk
Date: Tue May 3 15:02:43 2005
New Revision: 11855
Modified:
py/dist/py/test/defaultconftest.py
py/dist/py/test/session.py
py/dist/py/test/testing/test_session.py
Log:
flesh out keyword support, you can supply a google-style
keyword expression, e.g.
py.test -k "something -otherthing"
will run tests that have something but not otherthing
in their test name.
Modified: py/dist/py/test/defaultconftest.py
==============================================================================
--- py/dist/py/test/defaultconftest.py (original)
+++ py/dist/py/test/defaultconftest.py Tue May 3 15:02:43 2005
@@ -23,7 +23,7 @@
help="disable catching of sys.stdout/stderr output."),
Option('-k',
action="store", dest="keyword", default='',
- help="select tests if they match the given keyword"),
+ help="only run test items matching the given (google-style) keyword expression"),
Option('-l', '--showlocals',
action="store_true", dest="showlocals", default=False,
help="show locals in tracebacks (disabled by default)"),
Modified: py/dist/py/test/session.py
==============================================================================
--- py/dist/py/test/session.py (original)
+++ py/dist/py/test/session.py Tue May 3 15:02:43 2005
@@ -84,18 +84,29 @@
finally:
colitem.finishcapture()
+ def skipbykeyword(self, colitem):
+ keyword = self.config.option.keyword
+ if not keyword:
+ return
+ chain = colitem.listchain()
+ for key in filter(None, keyword.split()):
+ eor = key[:1] == '-'
+ if eor:
+ key = key[1:]
+ if not (eor ^ self._matchonekeyword(key, chain)):
+ py.test.skip("test not selected by keyword %r" %(keyword,))
+
+ def _matchonekeyword(self, key, chain):
+ for subitem in chain:
+ if subitem.haskeyword(key):
+ return True
+ return False
+
def run(self, colitem):
if self.config.option.collectonly and isinstance(colitem, py.test.Item):
return
if isinstance(colitem, py.test.Item):
- keyword = self.config.option.keyword
- if keyword:
- for subitem in colitem.listchain():
- if subitem.haskeyword(keyword):
- break
- else:
- py.test.skip("test not selected by keyword %r" %(keyword,))
-
+ self.skipbykeyword(colitem)
res = colitem.run()
if res is None:
return py.test.Item.Passed()
Modified: py/dist/py/test/testing/test_session.py
==============================================================================
--- py/dist/py/test/testing/test_session.py (original)
+++ py/dist/py/test/testing/test_session.py Tue May 3 15:02:43 2005
@@ -66,17 +66,21 @@
import py
class Class(py.test.collect.Class):
def haskeyword(self, keyword):
- return keyword == 'XXX' or \
+ return keyword == 'xxx' or \
super(Class, self).haskeyword(keyword)
"""))
- config, args = py.test.Config.parse(['-k', 'XXX'])
- session = config.getsessionclass()(config)
- session.main([o])
- l = session.getitemoutcomepairs(py.test.Item.Passed)
- assert len(l) == 1
- assert l[0][0].name == 'test_2'
- l = session.getitemoutcomepairs(py.test.Item.Skipped)
- assert l[0][0].name == 'test_1'
+ for keyword in ('xxx', 'xxx test_2', 'TestClass', 'xxx -test_1',
+ 'TestClass test_2', 'xxx TestClass test_2',):
+ f = StringIO()
+ config, args = py.test.Config.parse(['-k', keyword])
+ session = config.getsessionclass()(config, f)
+ session.main([o])
+ print "keyword", repr(keyword)
+ l = session.getitemoutcomepairs(py.test.Item.Passed)
+ assert len(l) == 1
+ assert l[0][0].name == 'test_2'
+ l = session.getitemoutcomepairs(py.test.Item.Skipped)
+ assert l[0][0].name == 'test_1'
#f = open('/tmp/logfile', 'wa')
class TestTerminalSession:
@@ -182,6 +186,10 @@
def test_capturing():
print 42
print >>py.std.sys.stderr, 23
+ def test_capturing_error():
+ print 1
+ print >>py.std.sys.stderr, 2
+ raise ValueError
"""))
conftest = o.join('conftest.py').write(py.code.Source("""
import py
@@ -209,7 +217,8 @@
assert out.find('module level output') != -1
allout = self.file.getvalue()
print "allout:", allout
- assert allout.find('module level output') != -1
+ assert allout.find('module level output') != -1, (
+ "session didn't show module output")
def test_raises_output(self):
o = tmpdir.ensure('raisestest', dir=1)
More information about the pytest-commit
mailing list