{"id":13685638,"url":"https://github.com/xmlrunner/unittest-xml-reporting","last_synced_at":"2025-05-15T07:05:07.611Z","repository":{"id":444580,"uuid":"67012","full_name":"xmlrunner/unittest-xml-reporting","owner":"xmlrunner","description":"unittest-based test runner with Ant/JUnit like XML reporting.","archived":false,"fork":false,"pushed_at":"2024-08-17T10:29:15.000Z","size":381,"stargazers_count":300,"open_issues_count":26,"forks_count":138,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-11T15:57:15.221Z","etag":null,"topics":["jenkins","junit-xml","nose","pytest","python","test-runner","unittest","xml-report","xunit","xunit-tests"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xmlrunner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2008-10-23T22:28:00.000Z","updated_at":"2025-04-09T13:42:42.000Z","dependencies_parsed_at":"2024-06-18T12:28:18.143Z","dependency_job_id":"41dde99b-a346-4db0-a6b7-5a3a09f2d82a","html_url":"https://github.com/xmlrunner/unittest-xml-reporting","commit_stats":{"total_commits":374,"total_committers":56,"mean_commits":6.678571428571429,"dds":0.7459893048128342,"last_synced_commit":"3a2be20177ec6e396d23eecb68d38d410c2ef7a5"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmlrunner%2Funittest-xml-reporting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmlrunner%2Funittest-xml-reporting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmlrunner%2Funittest-xml-reporting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmlrunner%2Funittest-xml-reporting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xmlrunner","download_url":"https://codeload.github.com/xmlrunner/unittest-xml-reporting/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254292040,"owners_count":22046426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jenkins","junit-xml","nose","pytest","python","test-runner","unittest","xml-report","xunit","xunit-tests"],"created_at":"2024-08-02T14:00:55.017Z","updated_at":"2025-05-15T07:05:02.597Z","avatar_url":"https://github.com/xmlrunner.png","language":"Python","readme":"[![License](https://img.shields.io/pypi/l/unittest-xml-reporting.svg)](https://pypi.python.org/pypi/unittest-xml-reporting/)\n[![Latest Version](https://img.shields.io/pypi/v/unittest-xml-reporting.svg)](https://pypi.python.org/pypi/unittest-xml-reporting/)\n[![Development Status](https://img.shields.io/pypi/status/unittest-xml-reporting.svg)](https://pypi.python.org/pypi/unittest-xml-reporting/)\n[![Documentation Status](https://readthedocs.org/projects/unittest-xml-reporting/badge/?version=latest)](http://unittest-xml-reporting.readthedocs.io/en/latest/?badge=latest)\n\n[![codecov.io Coverage Status](https://codecov.io/github/xmlrunner/unittest-xml-reporting/coverage.svg?branch=master)](https://codecov.io/github/xmlrunner/unittest-xml-reporting?branch=master)\n[![Coveralls Coverage Status](https://coveralls.io/repos/xmlrunner/unittest-xml-reporting/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/xmlrunner/unittest-xml-reporting?branch=master)\n[![Requirements Status](https://requires.io/github/xmlrunner/unittest-xml-reporting/requirements.svg?branch=master)](https://requires.io/github/xmlrunner/unittest-xml-reporting/requirements/?branch=master)\n\n# unittest-xml-reporting (aka xmlrunner)\n\nA unittest test runner that can save test results to XML files in xUnit format.\nThe files can be consumed by a wide range of tools, such as build systems, IDEs\nand continuous integration servers.\n\n\n## Requirements\n\n* Python 3.7+\n* Please note Python 3.6 end-of-life was in Dec 2021, last version supporting 3.6 was 3.1.0\n* Please note Python 3.5 end-of-life was in Sep 2020, last version supporting 3.5 was 3.1.0\n* Please note Python 2.7 end-of-life was in Jan 2020, last version supporting 2.7 was 2.5.2\n* Please note Python 3.4 end-of-life was in Mar 2019, last version supporting 3.4 was 2.5.2\n* Please note Python 2.6 end-of-life was in Oct 2013, last version supporting 2.6 was 1.14.0\n\n\n## Limited support for `unittest.TestCase.subTest`\n\nhttps://docs.python.org/3/library/unittest.html#unittest.TestCase.subTest\n\n`unittest` has the concept of sub-tests for a `unittest.TestCase`; this doesn't map well to an existing xUnit concept, so you won't find it in the schema. What that means, is that you lose some granularity\nin the reports for sub-tests.\n\n`unittest` also does not report successful sub-tests, so the accounting won't be exact.\n\n## Jenkins plugins\n\n- Jenkins JUnit plugin : https://plugins.jenkins.io/junit/\n- Jenkins xUnit plugin : https://plugins.jenkins.io/xunit/\n\n### Jenkins JUnit plugin\n\nThis plugin does not perform XSD validation (at time of writing) and should parse the XML file without issues.\n\n### Jenkins xUnit plugin version 1.100\n\n- [Jenkins (junit-10.xsd), xunit plugin (2014-2018)](https://github.com/jenkinsci/xunit-plugin/blob/14c6e39c38408b9ed6280361484a13c6f5becca7/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd), version `1.100`.\n\nThis plugin does perfom XSD validation and uses the more lax XSD. This should parse the XML file without issues.\n\n### Jenkins xUnit plugin version 1.104+\n\n- [Jenkins (junit-10.xsd), xunit plugin (2018-current)](https://github.com/jenkinsci/xunit-plugin/blob/ae25da5089d4f94ac6c4669bf736e4d416cc4665/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd), version `1.104`+.\n\nThis plugin does perfom XSD validation and uses the more strict XSD.\n\nSee https://github.com/xmlrunner/unittest-xml-reporting/issues/209\n\n```\nimport io\nimport unittest\nimport xmlrunner\n\n# run the tests storing results in memory\nout = io.BytesIO()\nunittest.main(\n    testRunner=xmlrunner.XMLTestRunner(output=out),\n    failfast=False, buffer=False, catchbreak=False, exit=False)\n```\n\nTransform the results removing extra attributes.\n```\nfrom xmlrunner.extra.xunit_plugin import transform\n\nwith open('TEST-report.xml', 'wb') as report:\n    report.write(transform(out.getvalue()))\n\n```\n\n## JUnit Schema ?\n\nThere are many tools claiming to write JUnit reports, so you will find many schemas with minor differences.\n\nWe used the XSD that was available in the Jenkins xUnit plugin version `1.100`; a copy is available under `tests/vendor/jenkins/xunit-plugin/.../junit-10.xsd` (see attached license).\n\nYou may also find these resources useful:\n\n- https://stackoverflow.com/questions/4922867/what-is-the-junit-xml-format-specification-that-hudson-supports\n- https://stackoverflow.com/questions/11241781/python-unittests-in-jenkins\n- [JUnit-Schema (JUnit.xsd)](https://github.com/windyroad/JUnit-Schema/blob/master/JUnit.xsd)\n- [Windyroad (JUnit.xsd)](http://windyroad.com.au/dl/Open%20Source/JUnit.xsd)\n- [a gist (Jenkins xUnit test result schema)](https://gist.github.com/erikd/4192748)\n\n\n## Installation\n\nThe easiest way to install unittest-xml-reporting is via\n[Pip](http://www.pip-installer.org):\n\n````bash\n$ pip install unittest-xml-reporting\n````\n\nIf you use Git and want to get the latest *development* version:\n\n````bash\n$ git clone https://github.com/xmlrunner/unittest-xml-reporting.git\n$ cd unittest-xml-reporting\n$ sudo python setup.py install\n````\n\nOr get the latest *development* version as a tarball:\n\n````bash\n$ wget https://github.com/xmlrunner/unittest-xml-reporting/archive/master.zip\n$ unzip master.zip\n$ cd unittest-xml-reporting\n$ sudo python setup.py install\n````\n\nOr you can manually download the latest released version from\n[PyPI](https://pypi.python.org/pypi/unittest-xml-reporting/).\n\n\n## Command-line\n\n````bash\npython -m xmlrunner [options]\npython -m xmlrunner discover [options]\n\n# help\npython -m xmlrunner -h\n````\n\ne.g. \n````bash\npython -m xmlrunner discover -t ~/mycode/tests -o /tmp/build/junit-reports\n````\n\n## Usage\n\nThe script below, adapted from the\n[unittest](http://docs.python.org/library/unittest.html), shows how to use\n`XMLTestRunner` in a very simple way. In fact, the only difference between\nthis script and the original one is the last line:\n\n````python\nimport random\nimport unittest\nimport xmlrunner\n\nclass TestSequenceFunctions(unittest.TestCase):\n\n    def setUp(self):\n        self.seq = list(range(10))\n\n    @unittest.skip(\"demonstrating skipping\")\n    def test_skipped(self):\n        self.fail(\"shouldn't happen\")\n\n    def test_shuffle(self):\n        # make sure the shuffled sequence does not lose any elements\n        random.shuffle(self.seq)\n        self.seq.sort()\n        self.assertEqual(self.seq, list(range(10)))\n\n        # should raise an exception for an immutable sequence\n        self.assertRaises(TypeError, random.shuffle, (1,2,3))\n\n    def test_choice(self):\n        element = random.choice(self.seq)\n        self.assertTrue(element in self.seq)\n\n    def test_sample(self):\n        with self.assertRaises(ValueError):\n            random.sample(self.seq, 20)\n        for element in random.sample(self.seq, 5):\n            self.assertTrue(element in self.seq)\n\nif __name__ == '__main__':\n    unittest.main(\n        testRunner=xmlrunner.XMLTestRunner(output='test-reports'),\n        # these make sure that some options that are not applicable\n        # remain hidden from the help menu.\n        failfast=False, buffer=False, catchbreak=False)\n````\n\n### Reporting to a single file\n\n````python\nif __name__ == '__main__':\n    with open('/path/to/results.xml', 'wb') as output:\n        unittest.main(\n            testRunner=xmlrunner.XMLTestRunner(output=output),\n            failfast=False, buffer=False, catchbreak=False)\n````\n\n### Doctest support\n\nThe XMLTestRunner can also be used to report on docstrings style tests.\n\n````python\nimport doctest\nimport xmlrunner\n\ndef twice(n):\n    \"\"\"\n    \u003e\u003e\u003e twice(5)\n    10\n    \"\"\"\n    return 2 * n\n\nclass Multiplicator(object):\n    def threetimes(self, n):\n        \"\"\"\n        \u003e\u003e\u003e Multiplicator().threetimes(5)\n        15\n        \"\"\"\n        return 3 * n\n\nif __name__ == \"__main__\":\n    suite = doctest.DocTestSuite()\n    xmlrunner.XMLTestRunner().run(suite)\n````\n\n### Django support\n\nIn order to plug `XMLTestRunner` to a Django project, add the following\nto your `settings.py`:\n\n````python\nTEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner'\n````\n\nAlso, the following settings are provided so you can fine tune the reports:\n\n|setting|default|values|description|\n|-|-|-|-|\n|`TEST_OUTPUT_VERBOSE`|`1`|`0\\|1\\|2`|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.|\n|`TEST_OUTPUT_DESCRIPTIONS`|`False`|`True\\|False`|If your test methods contains docstrings, you can display such docstrings instead of display the test name (ex: `module.TestCase.test_method`).\u003cbr\u003eIn order to use this feature, you have to enable verbose output by setting `TEST_OUTPUT_VERBOSE = 2`.\u003cbr\u003eOnly effects stdout and not XML output.|\n|`TEST_OUTPUT_DIR`|`\".\"`|`\u003cstr\u003e`|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.|\n|`TEST_OUTPUT_FILE_NAME`|`None`|`\u003cstr\u003e`|Tells the test runner to output a single XML report with this filename under `os.path.join(TEST_OUTPUT_DIR, TEST_OUTPUT_FILE_NAME)`.\u003cbr\u003ePlease note that for long running tests, this will keep the results in memory for a longer time than multiple reports, and may use up more resources.|\n\n\n## Contributing\n\nWe are always looking for good contributions, so please just fork the\nrepository and send pull requests (with tests!).\n\nIf you would like write access to the repository, or become a maintainer,\nfeel free to get in touch.\n\n\n### Testing changes with `tox`\n\nPlease use `tox` to test your changes before sending a pull request.\nYou can find more information about `tox` at \u003chttps://testrun.org/tox/latest/\u003e.\n\n```bash\n$ pip install tox\n\n# basic sanity test, friendly output\n$ tox -e pytest\n\n# all combinations\n$ tox\n```\n","funding_links":[],"categories":["Tests","Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxmlrunner%2Funittest-xml-reporting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxmlrunner%2Funittest-xml-reporting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxmlrunner%2Funittest-xml-reporting/lists"}