9
9
By using the ``py.test.mark`` helper you can instantiate
10
decorators that will set named meta data on test functions.
10
decorators that will set named meta data on test functions.
12
Marking a single function
12
Marking a single function
13
13
----------------------------------------------------
15
15
You can "mark" a test function with meta data like this::
17
17
@py.test.mark.webtest
18
18
def test_send_http():
21
This will set a "Marker" instance as a function attribute named "webtest".
21
This will set a "Marker" instance as a function attribute named "webtest".
22
22
You can also specify parametrized meta data like this::
24
24
@py.test.mark.webtest(firefox=30)
40
40
.. _`scoped-marking`:
42
Marking classes or modules
42
Marking whole classes or modules
43
43
----------------------------------------------------
45
To mark all methods of a class set a ``pytestmark`` attribute like this::
45
If you are programming with Python2.6 you may use ``py.test.mark`` decorators
46
with classes to apply markers to all its test methods::
50
def test_startup(self):
52
def test_startup_and_more(self):
55
This is equivalent to directly applying the decorator to the
58
To remain compatible with Python2.5 you can also set a
59
``pytestmark`` attribute on a TestClass like this::
50
64
pytestmark = py.test.mark.webtest
52
You can re-use the same markers that you would use for decorating
53
a function - in fact this marker decorator will be applied
54
to all test methods of the class.
66
or if you need to use multiple markers you can use a list::
71
pytestmark = [py.test.mark.webtest, pytest.mark.slowtest]
56
73
You can also set a module level marker::
59
76
pytestmark = py.test.mark.webtest
61
in which case then the marker decorator will be applied to all functions and
62
methods defined in the module.
64
The order in which marker functions are called is this::
66
per-function (upon import of module already)
70
Later called markers may overwrite previous key-value settings.
71
Positional arguments are all appended to the same 'args' list
78
in which case it will be applied to all functions and
79
methods defined in the module.
74
81
Using "-k MARKNAME" to select tests
75
82
----------------------------------------------------
83
90
=========================================
86
1. Download `pytest_mark.py`_ plugin source code
87
2. put it somewhere as ``pytest_mark.py`` into your import path
93
1. Download `pytest_mark.py`_ plugin source code
94
2. put it somewhere as ``pytest_mark.py`` into your import path
88
95
3. a subsequent ``py.test`` run will use your local version
90
Checkout customize_, other plugins_ or `get in contact`_.
97
Checkout customize_, other plugins_ or `get in contact`_.
92
99
.. include:: links.txt