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

« back to all changes in this revision

Viewing changes to doc/test/plugin/xdist.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:
6
6
.. contents::
7
7
  :local:
8
8
 
9
 
The `pytest-xdist`_ plugin extends py.test with some unique 
 
9
The `pytest-xdist`_ plugin extends py.test with some unique
10
10
test execution modes:
11
11
 
12
12
* Looponfail: run your tests repeatedly in a subprocess.  After each run py.test
13
13
  waits until a file in your project changes and then re-runs the previously
14
14
  failing tests.  This is repeated until all tests pass after which again
15
 
  a full run is performed. 
 
15
  a full run is performed.
16
16
 
17
17
* Load-balancing: if you have multiple CPUs or hosts you can use
18
 
  those for a combined test run.  This allows to speed up 
19
 
  development or to use special resources of remote machines.  
 
18
  those for a combined test run.  This allows to speed up
 
19
  development or to use special resources of remote machines.
20
20
 
21
21
* Multi-Platform coverage: you can specify different Python interpreters
22
 
  or different platforms and run tests in parallel on all of them. 
 
22
  or different platforms and run tests in parallel on all of them.
23
23
 
24
 
Before running tests remotely, ``py.test`` efficiently synchronizes your 
25
 
program source code to the remote place.  All test results 
26
 
are reported back and displayed to your local test session.  
 
24
Before running tests remotely, ``py.test`` efficiently synchronizes your
 
25
program source code to the remote place.  All test results
 
26
are reported back and displayed to your local test session.
27
27
You may specify different Python versions and interpreters.
28
28
 
29
29
.. _`pytest-xdist`: http://pypi.python.org/pypi/pytest-xdist
38
38
 
39
39
    py.test -n NUM
40
40
 
41
 
Especially for longer running tests or tests requiring 
42
 
a lot of IO this can lead to considerable speed ups. 
43
 
 
44
 
 
45
 
Running tests in a Python subprocess 
 
41
Especially for longer running tests or tests requiring
 
42
a lot of IO this can lead to considerable speed ups.
 
43
 
 
44
 
 
45
Running tests in a Python subprocess
46
46
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
47
47
 
48
48
To instantiate a python2.4 sub process and send tests to it, you may type::
50
50
    py.test -d --tx popen//python=python2.4
51
51
 
52
52
This will start a subprocess which is run with the "python2.4"
53
 
Python interpreter, found in your system binary lookup path. 
 
53
Python interpreter, found in your system binary lookup path.
54
54
 
55
55
If you prefix the --tx option value like this::
56
56
 
57
57
    --tx 3*popen//python=python2.4
58
58
 
59
59
then three subprocesses would be created and tests
60
 
will be load-balanced across these three processes. 
 
60
will be load-balanced across these three processes.
61
61
 
62
62
 
63
63
Sending tests to remote SSH accounts
64
64
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
65
65
 
66
 
Suppose you have a package ``mypkg`` which contains some 
 
66
Suppose you have a package ``mypkg`` which contains some
67
67
tests that you can successfully run locally. And you
68
 
have a ssh-reachable machine ``myhost``.  Then    
 
68
have a ssh-reachable machine ``myhost``.  Then
69
69
you can ad-hoc distribute your tests by typing::
70
70
 
71
71
    py.test -d --tx ssh=myhostpopen --rsyncdir mypkg mypkg
72
72
 
73
 
This will synchronize your ``mypkg`` package directory 
74
 
to an remote ssh account and then locally collect tests 
75
 
and send them to remote places for execution.  
 
73
This will synchronize your ``mypkg`` package directory
 
74
to an remote ssh account and then locally collect tests
 
75
and send them to remote places for execution.
76
76
 
77
 
You can specify multiple ``--rsyncdir`` directories 
78
 
to be sent to the remote side. 
 
77
You can specify multiple ``--rsyncdir`` directories
 
78
to be sent to the remote side.
79
79
 
80
80
**NOTE:** For py.test to collect and send tests correctly
81
81
you not only need to make sure all code and tests
82
82
directories are rsynced, but that any test (sub) directory
83
83
also has an ``__init__.py`` file because internally
84
84
py.test references tests as a fully qualified python
85
 
module path.  **You will otherwise get strange errors** 
 
85
module path.  **You will otherwise get strange errors**
86
86
during setup of the remote side.
87
87
 
88
88
Sending tests to remote Socket Servers
89
89
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
90
90
 
91
 
Download the single-module `socketserver.py`_ Python program 
 
91
Download the single-module `socketserver.py`_ Python program
92
92
and run it like this::
93
93
 
94
94
    python socketserver.py
95
95
 
96
96
It will tell you that it starts listening on the default
97
 
port.  You can now on your home machine specify this 
 
97
port.  You can now on your home machine specify this
98
98
new socket host with something like this::
99
99
 
100
100
    py.test -d --tx socket=192.168.1.102:8888 --rsyncdir mypkg mypkg
102
102
 
103
103
.. _`atonce`:
104
104
 
105
 
Running tests on many platforms at once 
 
105
Running tests on many platforms at once
106
106
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
107
107
 
108
108
The basic command to run tests on multiple platforms is::
109
109
 
110
 
    py.test --dist=each --tx=spec1 --tx=spec2 
 
110
    py.test --dist=each --tx=spec1 --tx=spec2
111
111
 
112
112
If you specify a windows host, an OSX host and a Linux
113
 
environment this command will send each tests to all 
 
113
environment this command will send each tests to all
114
114
platforms - and report back failures from all platforms
115
 
at once.   The specifications strings use the `xspec syntax`_. 
 
115
at once.   The specifications strings use the `xspec syntax`_.
116
116
 
117
117
.. _`xspec syntax`: http://codespeak.net/execnet/trunk/basics.html#xspec
118
118
 
123
123
Specifying test exec environments in a conftest.py
124
124
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
125
125
 
126
 
Instead of specifying command line options, you can 
 
126
Instead of specifying command line options, you can
127
127
put options values in a ``conftest.py`` file like this::
128
128
 
129
 
    pytest_option_tx = ['ssh=myhost//python=python2.5', 'popen//python=python2.5']
130
 
    pytest_option_dist = True
 
129
    option_tx = ['ssh=myhost//python=python2.5', 'popen//python=python2.5']
 
130
    option_dist = True
131
131
 
132
 
Any commandline ``--tx`` specifictions  will add to the list of available execution
133
 
environments. 
 
132
Any commandline ``--tx`` specifictions  will add to the list of
 
133
available execution environments.
134
134
 
135
135
Specifying "rsync" dirs in a conftest.py
136
136
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
156
156
    box each test run in a separate process (unix)
157
157
``--dist=distmode``
158
158
    set mode for distributing tests to exec environments.
159
 
    
 
159
 
160
160
    each: send each test to each available environment.
161
 
    
 
161
 
162
162
    load: send each test to available environment.
163
 
    
 
163
 
164
164
    (default) no: run tests inprocess, don't distribute.
165
165
``--tx=xspec``
166
166
    add a test execution environment. some examples: --tx popen//python=python2.5 --tx socket=192.168.1.102:8888 --tx ssh=user@codespeak.net//chdir=testcache
169
169
``--rsyncdir=dir1``
170
170
    add directory for rsyncing to remote tx nodes.
171
171
 
172
 
Start improving this plugin in 30 seconds
173
 
=========================================
174
 
 
175
 
 
176
 
1. Download `plugin.py`_ plugin source code 
177
 
2. put it somewhere as ``plugin.py`` into your import path 
178
 
3. a subsequent ``py.test`` run will use your local version
179
 
 
180
 
Checkout customize_, other plugins_ or `get in contact`_. 
181
 
 
182
172
.. include:: links.txt