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