File: README.markdown

package info (click to toggle)
unittest-xml-reporting 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 100 kB
  • ctags: 57
  • sloc: python: 304; makefile: 7
file content (106 lines) | stat: -rw-r--r-- 3,237 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# unittest-xml-reporting

unittest-xml-reporting is a unittest test runner that can save test results
to XML files that can be consumed by a wide range of tools, such as build
systems, IDEs and continuous integration servers.

## Requirements

* Python 2.5+

## Installation

The easiest way to install unittest-xml-reporting is via
[EasyInstall](http://peak.telecommunity.com/DevCenter/EasyInstall). Follow
[these instructions](http://pypi.python.org/pypi/setuptools) to install
EasyInstall if you don't have it already.

Then, execute the following command line to install the latest stable version
of unittest-xml-reporting:

````bash
$ sudo easy_install unittest-xml-reporting
````

If you use Git and want to get the latest *development* version:

````bash
$ git clone git://github.com/danielfm/unittest-xml-reporting.git
$ cd unittest-xml-reporting
$ sudo python setup.py install
````

Or get the latest *development* version as a tarball:

````bash
$ wget http://github.com/danielfm/unittest-xml-reporting/tarball/master
$ tar zxf danielfm-unittest-xml-reporting-XXXXXXXXXXXXXXXX.tar.gz
$ cd danielfm-unittest-xml-reporting-XXXXXXXXXXXXXXXX
$ sudo python setup.py install
````

## Usage

The script below, adapted from the
[unittest](http://docs.python.org/library/unittest.html), shows how to use
`XMLTestRunner` in a very simple way. In fact, the only difference between
this script and the original one is the last line:

````python
import random
import unittest
import xmlrunner

class TestSequenceFunctions(unittest.TestCase):
    def setUp(self):
        self.seq = range(10)

    def test_shuffle(self):
        # make sure the shuffled sequence does not lose any elements
        random.shuffle(self.seq)
        self.seq.sort()
        self.assertEqual(self.seq, range(10))

    def test_choice(self):
        element = random.choice(self.seq)
        self.assert_(element in self.seq)

    def test_sample(self):
        self.assertRaises(ValueError, random.sample, self.seq, 20)
        for element in random.sample(self.seq, 5):
            self.assert_(element in self.seq)

if __name__ == '__main__':
    unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))
````

### Django 1.2

In order to plug `XMLTestRunner` to a Django project, add the following
to your `settings.py`:

````python
TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner'
````

Also, the following settings are provided so you can fine tune the reports:

**TEST_OUTPUT_VERBOSE** (Default: `1`)

Besides the XML reports generated by the test runner, a bunch of useful
information is printed to the `sys.stderr` stream, just like the
`TextTestRunner` does. Use this setting to choose between a verbose and a
non-verbose output.

**TEST_OUTPUT_DESCRIPTIONS** (Default: `False`)

If your test methods contains docstrings, you can display such docstrings
instead of display the test name (ex: `module.TestCase.test_method`). In
order to use this feature, you have to enable verbose output by setting
`TEST_OUTPUT_VERBOSE = 2`.

**TEST_OUTPUT_DIR** (Default: `"."`)

Tells the test runner where to put the XML reports. If the directory
couldn't be found, the test runner will try to create it before
generate the XML files.