~crunch.io/ubuntu/precise/codespeak-lib/unstable

« back to all changes in this revision

Viewing changes to doc/test/plugin/mark.txt

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-08-01 16:24:01 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100801162401-g37v49d1p148alpm
Tags: 1.3.3-1
* New upstream release.
* Bump Standards-Version to 3.9.1.
* Fix typo in py.test manpage.
* Prefer Breaks: over Conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
  :local:
8
8
 
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.
11
11
 
12
 
Marking a single function 
 
12
Marking a single function
13
13
----------------------------------------------------
14
14
 
15
15
You can "mark" a test function with meta data like this::
16
16
 
17
17
    @py.test.mark.webtest
18
18
    def test_send_http():
19
 
        ... 
 
19
        ...
20
20
 
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::
23
23
 
24
24
    @py.test.mark.webtest(firefox=30)
39
39
 
40
40
.. _`scoped-marking`:
41
41
 
42
 
Marking classes or modules 
 
42
Marking whole classes or modules
43
43
----------------------------------------------------
44
44
 
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::
 
47
 
 
48
    @py.test.mark.webtest
 
49
    class TestClass:
 
50
        def test_startup(self):
 
51
            ...
 
52
        def test_startup_and_more(self):
 
53
            ...
 
54
 
 
55
This is equivalent to directly applying the decorator to the
 
56
two test functions.
 
57
 
 
58
To remain compatible with Python2.5 you can also set a
 
59
``pytestmark`` attribute on a TestClass like this::
46
60
 
47
61
    import py
48
62
 
49
63
    class TestClass:
50
64
        pytestmark = py.test.mark.webtest
51
65
 
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::
 
67
 
 
68
    import py
 
69
 
 
70
    class TestClass:
 
71
        pytestmark = [py.test.mark.webtest, pytest.mark.slowtest]
55
72
 
56
73
You can also set a module level marker::
57
74
 
58
75
    import py
59
76
    pytestmark = py.test.mark.webtest
60
77
 
61
 
in which case then the marker decorator will be applied to all functions and 
62
 
methods defined in the module.  
63
 
 
64
 
The order in which marker functions are called is this::
65
 
 
66
 
    per-function (upon import of module already) 
67
 
    per-class
68
 
    per-module 
69
 
 
70
 
Later called markers may overwrite previous key-value settings. 
71
 
Positional arguments are all appended to the same 'args' list 
72
 
of the Marker object. 
 
78
in which case it will be applied to all functions and
 
79
methods defined in the module.
73
80
 
74
81
Using "-k MARKNAME" to select tests
75
82
----------------------------------------------------
83
90
=========================================
84
91
 
85
92
 
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
89
96
 
90
 
Checkout customize_, other plugins_ or `get in contact`_. 
 
97
Checkout customize_, other plugins_ or `get in contact`_.
91
98
 
92
99
.. include:: links.txt