xref: /honee/tests/junit-xml/README.rst (revision 0006be33bc3a095c7a40443db044019362bd3e1c)
1*0006be33SJames Wrightpython-junit-xml
2*0006be33SJames Wright================
3*0006be33SJames Wright.. image:: https://travis-ci.org/kyrus/python-junit-xml.png?branch=master
4*0006be33SJames Wright
5*0006be33SJames WrightAbout
6*0006be33SJames Wright-----
7*0006be33SJames Wright
8*0006be33SJames WrightA Python module for creating JUnit XML test result documents that can be
9*0006be33SJames Wrightread by tools such as Jenkins or Bamboo. If you are ever working with test tool or
10*0006be33SJames Wrighttest suite written in Python and want to take advantage of Jenkins' or Bamboo's
11*0006be33SJames Wrightpretty graphs and test reporting capabilities, this module will let you
12*0006be33SJames Wrightgenerate the XML test reports.
13*0006be33SJames Wright
14*0006be33SJames Wright*As there is no definitive Jenkins JUnit XSD that I could find, the XML
15*0006be33SJames Wrightdocuments created by this module support a schema based on Google
16*0006be33SJames Wrightsearches and the Jenkins JUnit XML reader source code. File a bug if
17*0006be33SJames Wrightsomething doesn't work like you expect it to.
18*0006be33SJames WrightFor Bamboo situation is the same.*
19*0006be33SJames Wright
20*0006be33SJames WrightInstallation
21*0006be33SJames Wright------------
22*0006be33SJames Wright
23*0006be33SJames WrightInstall using pip or easy_install:
24*0006be33SJames Wright
25*0006be33SJames Wright::
26*0006be33SJames Wright
27*0006be33SJames Wright	pip install junit-xml
28*0006be33SJames Wright	or
29*0006be33SJames Wright	easy_install junit-xml
30*0006be33SJames Wright
31*0006be33SJames WrightYou can also clone the Git repository from Github and install it manually:
32*0006be33SJames Wright
33*0006be33SJames Wright::
34*0006be33SJames Wright
35*0006be33SJames Wright    git clone https://github.com/kyrus/python-junit-xml.git
36*0006be33SJames Wright    python setup.py install
37*0006be33SJames Wright
38*0006be33SJames WrightUsing
39*0006be33SJames Wright-----
40*0006be33SJames Wright
41*0006be33SJames WrightCreate a test suite, add a test case, and print it to the screen:
42*0006be33SJames Wright
43*0006be33SJames Wright.. code-block:: python
44*0006be33SJames Wright
45*0006be33SJames Wright    from junit_xml import TestSuite, TestCase
46*0006be33SJames Wright
47*0006be33SJames Wright    test_cases = [TestCase('Test1', 'some.class.name', 123.345, 'I am stdout!', 'I am stderr!')]
48*0006be33SJames Wright    ts = TestSuite("my test suite", test_cases)
49*0006be33SJames Wright    # pretty printing is on by default but can be disabled using prettyprint=False
50*0006be33SJames Wright    print(TestSuite.to_xml_string([ts]))
51*0006be33SJames Wright
52*0006be33SJames WrightProduces the following output
53*0006be33SJames Wright
54*0006be33SJames Wright.. code-block:: xml
55*0006be33SJames Wright
56*0006be33SJames Wright    <?xml version="1.0" ?>
57*0006be33SJames Wright    <testsuites>
58*0006be33SJames Wright        <testsuite errors="0" failures="0" name="my test suite" tests="1">
59*0006be33SJames Wright            <testcase classname="some.class.name" name="Test1" time="123.345000">
60*0006be33SJames Wright                <system-out>
61*0006be33SJames Wright                    I am stdout!
62*0006be33SJames Wright                </system-out>
63*0006be33SJames Wright                <system-err>
64*0006be33SJames Wright                    I am stderr!
65*0006be33SJames Wright                </system-err>
66*0006be33SJames Wright            </testcase>
67*0006be33SJames Wright        </testsuite>
68*0006be33SJames Wright    </testsuites>
69*0006be33SJames Wright
70*0006be33SJames WrightWriting XML to a file:
71*0006be33SJames Wright
72*0006be33SJames Wright.. code-block:: python
73*0006be33SJames Wright
74*0006be33SJames Wright    # you can also write the XML to a file and not pretty print it
75*0006be33SJames Wright    with open('output.xml', 'w') as f:
76*0006be33SJames Wright        TestSuite.to_file(f, [ts], prettyprint=False)
77*0006be33SJames Wright
78*0006be33SJames WrightSee the docs and unit tests for more examples.
79*0006be33SJames Wright
80*0006be33SJames WrightNOTE: Unicode characters identified as "illegal or discouraged" are automatically
81*0006be33SJames Wrightstripped from the XML string or file.
82*0006be33SJames Wright
83*0006be33SJames WrightRunning the tests
84*0006be33SJames Wright-----------------
85*0006be33SJames Wright
86*0006be33SJames Wright::
87*0006be33SJames Wright
88*0006be33SJames Wright    # activate your virtualenv
89*0006be33SJames Wright    pip install tox
90*0006be33SJames Wright    tox
91*0006be33SJames Wright
92*0006be33SJames WrightReleasing a new version
93*0006be33SJames Wright-----------------------
94*0006be33SJames Wright
95*0006be33SJames Wright1. Bump version in `setup.py`
96*0006be33SJames Wright2. Build distribution with `python setup.py sdist bdist_wheel`
97*0006be33SJames Wright3. Upload to Pypi with `twine upload dist/*`
98*0006be33SJames Wright4. Verify the new version was uploaded at https://pypi.org/project/junit-xml/#history
99