re-adding py.test.mark as documented (!) by adding pytest_keyword plugin

--HG--
branch : 1.0.x
This commit is contained in:
holger krekel 2009-06-28 13:19:43 +02:00
parent e412f695dd
commit bd8f68555d
7 changed files with 90 additions and 9 deletions

View File

@ -1,6 +1,8 @@
Changes between 1.0.0b3 and 1.0.0
=============================================
* re-added py.test.mark decorator for setting keywords on functions
* remove scope-argument from request.addfinalizer() because
request.cached_setup has the scope arg. TOOWTDI.

View File

@ -320,6 +320,7 @@ py/test/plugin/pytest_execnetcleanup.py
py/test/plugin/pytest_figleaf.py
py/test/plugin/pytest_hooklog.py
py/test/plugin/pytest_iocapture.py
py/test/plugin/pytest_keyword.py
py/test/plugin/pytest_monkeypatch.py
py/test/plugin/pytest_pdb.py
py/test/plugin/pytest_pocoo.py

View File

@ -237,13 +237,15 @@ keyword.
By default, all filename parts and
class/function names of a test function are put into the set
of keywords for a given test. You may specify additional
of keywords for a given test. You can specify additional
kewords like this::
@py.test.mark(webtest=True)
def test_send_http():
...
and then use those keywords to select tests.
disabling a test class
----------------------

View File

@ -19,7 +19,7 @@ For questions please check out http://pylib.org/contact.html
"""
from initpkg import initpkg
version = "1.0.0b5"
version = "1.0.0b6"
initpkg(__name__,
description = "py.test and pylib: advanced testing tool and networking lib",

View File

@ -10,5 +10,5 @@ Generator = py.test.collect.Generator
Function = py.test.collect.Function
Instance = py.test.collect.Instance
pytest_plugins = "default runner terminal xfail tmpdir execnetcleanup monkeypatch recwarn pdb".split()
pytest_plugins = "default runner terminal keyword xfail tmpdir execnetcleanup monkeypatch recwarn pdb".split()

View File

@ -0,0 +1,79 @@
"""
py.test.mark / keyword plugin
"""
import py
def pytest_namespace(config):
mark = KeywordDecorator({})
return {'mark': mark}
class KeywordDecorator:
""" decorator for setting function attributes. """
def __init__(self, keywords, lastname=None):
self._keywords = keywords
self._lastname = lastname
def __call__(self, func=None, **kwargs):
if func is None:
kw = self._keywords.copy()
kw.update(kwargs)
return KeywordDecorator(kw)
elif not hasattr(func, 'func_dict'):
kw = self._keywords.copy()
name = self._lastname
if name is None:
name = "mark"
kw[name] = func
return KeywordDecorator(kw)
func.func_dict.update(self._keywords)
return func
def __getattr__(self, name):
if name[0] == "_":
raise AttributeError(name)
kw = self._keywords.copy()
kw[name] = True
return self.__class__(kw, lastname=name)
def test_pytest_mark_getattr():
mark = KeywordDecorator({})
def f(): pass
mark.hello(f)
assert f.hello == True
mark.hello("test")(f)
assert f.hello == "test"
py.test.raises(AttributeError, "mark._hello")
py.test.raises(AttributeError, "mark.__str__")
def test_pytest_mark_call():
mark = KeywordDecorator({})
def f(): pass
mark(x=3)(f)
assert f.x == 3
def g(): pass
mark(g)
assert not g.func_dict
mark.hello(f)
assert f.hello == True
mark.hello("test")(f)
assert f.hello == "test"
mark("x1")(f)
assert f.mark == "x1"
def test_mark_plugin(testdir):
p = testdir.makepyfile("""
import py
pytest_plugins = "keyword"
@py.test.mark.hello
def test_hello():
assert hasattr(test_hello, 'hello')
""")
result = testdir.runpytest(p)
assert result.stdout.fnmatch_lines(["*passed*"])

View File

@ -1,8 +1,5 @@
"""
autogenerated by gensetup.py
setup file for 'py' package based on:
revision: 1181:8a8203ee5eb85837b6a40d95d861af42008d1a4c
"""
import os, sys
@ -35,7 +32,7 @@ def main():
name='py',
description='py.test and pylib: advanced testing tool and networking lib',
long_description = long_description,
version='1.0.0b5',
version='1.0.0b6',
url='http://pylib.org',
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],