fix issue89 - allow py.test.mark decorators to be used with classes

(if you are using >=python2.6)
also allow to have multiple markers applied at class level
and test and fix a bug with chained skip/xfail decorators:
if any of the conditions is true a test will be skipped/xfailed
with a explanation which condition evaluated to true.

--HG--
branch : trunk
This commit is contained in:
holger krekel
2010-05-21 18:11:47 +02:00
parent 67ec87e7f9
commit 4f7ef0b63f
7 changed files with 192 additions and 54 deletions
+21 -16
View File
@@ -39,38 +39,43 @@ and later access it with ``test_receive.webtest.args[0] == 'triangular``.
.. _`scoped-marking`:
Marking classes or modules
Marking whole classes or modules
----------------------------------------------------
To mark all methods of a class set a ``pytestmark`` attribute like this::
If you are programming with Python2.6 you may use ``py.test.mark`` decorators
with classes to apply markers to all its test methods::
@py.test.mark.webtest
class TestClass:
def test_startup(self):
...
This is equivalent to directly applying the decorator to the
``test_startup`` function.
To remain compatible with Python2.5 you can instead set a
``pytestmark`` attribute on a TestClass like this::
import py
class TestClass:
pytestmark = py.test.mark.webtest
You can re-use the same markers that you would use for decorating
a function - in fact this marker decorator will be applied
to all test methods of the class.
or if you need to use multiple markers::
import py
class TestClass:
pytestmark = [py.test.mark.webtest, pytest.mark.slowtest]
You can also set a module level marker::
import py
pytestmark = py.test.mark.webtest
in which case then the marker decorator will be applied to all functions and
in which case then it will be applied to all functions and
methods defined in the module.
The order in which marker functions are called is this::
per-function (upon import of module already)
per-class
per-module
Later called markers may overwrite previous key-value settings.
Positional arguments are all appended to the same 'args' list
of the Marker object.
Using "-k MARKNAME" to select tests
----------------------------------------------------
+12
View File
@@ -65,6 +65,18 @@ for skipping all methods of a test class based on platform::
#
The ``pytestmark`` decorator will be applied to each test function.
If your code targets python2.6 or above you can also use the
skipif decorator with classes::
@py.test.mark.skipif("sys.platform == 'win32'")
class TestPosixCalls:
def test_function(self):
# will not be setup or run under 'win32' platform
#
It is fine in both situations to use multiple "skipif" decorators
on a single function.
.. _`whole class- or module level`: mark.html#scoped-marking