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

« back to all changes in this revision

Viewing changes to doc/test/examples.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:
4
4
adding custom options
5
5
----------------------
6
6
 
7
 
py.test supports adding of standard optparse_ Options. 
8
 
A plugin may implement the ``addoption`` hook for registering 
9
 
custom options:: 
 
7
py.test supports adding of standard optparse_ Options.
 
8
A plugin may implement the ``addoption`` hook for registering
 
9
custom options::
10
10
 
11
11
    def pytest_addoption(parser):
12
 
        parser.addoption("-M", "--myopt", action="store", 
 
12
        parser.addoption("-M", "--myopt", action="store",
13
13
            help="specify string to set myopt")
14
14
 
15
15
    def pytest_configure(config):
16
16
        if config.option.myopt:
17
17
            # do action based on option value
18
18
            #
19
 
            
 
19
 
20
20
.. _optparse: http://docs.python.org/library/optparse.html
21
21
 
22
22
Working Examples
23
23
================
24
24
 
25
 
managing state at module, class and method level 
 
25
managing state at module, class and method level
26
26
------------------------------------------------------------
27
27
 
28
 
Here is a working example for what goes on when you setup modules, 
29
 
classes and methods:: 
 
28
Here is a working example for what goes on when you setup modules,
 
29
classes and methods::
30
30
 
31
31
    # [[from py/documentation/example/pytest/test_setup_flow_example.py]]
32
32
 
58
58
 
59
59
    import test_setup_flow_example
60
60
    setup_module(test_setup_flow_example)
61
 
       setup_class(TestStateFullThing) 
 
61
       setup_class(TestStateFullThing)
62
62
           instance = TestStateFullThing()
63
 
           setup_method(instance, instance.test_42) 
 
63
           setup_method(instance, instance.test_42)
64
64
              instance.test_42()
65
 
           setup_method(instance, instance.test_23) 
 
65
           setup_method(instance, instance.test_23)
66
66
              instance.test_23()
67
 
       teardown_class(TestStateFullThing) 
 
67
       teardown_class(TestStateFullThing)
68
68
    teardown_module(test_setup_flow_example)
69
69
 
70
 
Note that ``setup_class(TestStateFullThing)`` is called and not 
 
70
Note that ``setup_class(TestStateFullThing)`` is called and not
71
71
``TestStateFullThing.setup_class()`` which would require you
72
72
to insert ``setup_class = classmethod(setup_class)`` to make
73
73
your setup function callable. Did we mention that lazyness
74
 
is a virtue? 
 
74
is a virtue?