xmlunittest
Library using lxml and unittest for unit testing XML.
What it is and what it does
xmlunittest is a TestCase subclass that adds assertion methods for validating XML documents as structured data rather than raw strings. It uses lxml and XPath to let you write tests that check namespaces, element values, attribute presence, and document structure without being brittle to formatting changes or attribute reordering.
You extend XmlTestCase, call assertXmlDocument() to parse your XML, then use methods like assertXpathValues(), assertXmlNamespace(), and assertXpathsUniqueValue() to validate specific parts of the tree. This is useful when your code generates XML and you want tests that survive cosmetic changes to the output while still catching structural problems.
Use it for:
- Test XML output from code that generates configuration files, RSS feeds, or SOAP responses without brittle string comparisons.
- Validate that XML documents conform to expected namespaces and element structures using XPath queries.
- Check that optional XML elements and attributes are present or absent as expected in unit tests.
- Ensure attribute values match a set of allowed options across multiple elements in a single assertion.
- Verify uniqueness constraints on XML attributes across a document tree using XPath expressions.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Extends Python's unittest framework to compare XML documents structurally using XPath expressions and lxml, rather than comparing raw XML strings.
Yes, if you generate XML and use unittest. The package is stable, has no known vulnerabilities, and low install friction. Dormant maintenance is a minor concern—it suggests no active development, but the core functionality is straightforward and unlikely to break. Use it when string-based XML comparison would be fragile or unreadable.
Install
xmlunittest on PyPI
pip
pip install xmlunittestuv
uv add xmlunittestpoetry
poetry add xmlunittestInstalling xmlunittest
Before you install
Low friction: pure Python wheel with a single runtime dependency on lxml. Maintenance is dormant (762 days since last release) but the repository is not archived and the package is marked Production/Stable.
License in practice
MIT license is permissive; you can use this package freely in commercial and private projects with minimal restrictions.
Quickstart
from xmlunittest import XmlTestCase
class MyTest(XmlTestCase):
def test_xml(self):
data = b'<?xml version="1.0"?><root><item id="1"/></root>'
root = self.assertXmlDocument(data)
self.assertXpathValues(root, './item/@id', ('1',))
Requires lxml to be installed; lxml has C dependencies that may need compilation on some platforms.
Verify before relying
- Whether the package works with Python 3.13+ (classifiers list only up to 3.12)
- Whether dormant maintenance status affects real-world bug fixes or security updates going forward
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — lxml |
| Maintenance | dormant — 762 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,001,212/month — #4,537 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: xmlunittest-1.0.1-py3-none-any.whl
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
lxmllxml provides Python bindings to libxml2 and…
permissive · top 1,000 on PyPI
et-xmlfileet_xmlfile writes large XML files with minimal…
permissive · top 1,000 on PyPI
xunitparserParses JUnit/XUnit XML test result files and…
permissive · top 15,000 on PyPI
xmldiffxmldiff compares two XML files or trees and…
permissive · top 15,000 on PyPI
xsdataxsdata generates Python dataclasses from XML…
permissive · top 5,000 on PyPI
testtoolstesttools extends Python's standard unittest…
permissive · top 5,000 on PyPI
saxoncheSaxonC-HE is a Python wrapper for Saxon, an XML…
unclear · top 5,000 on PyPI
unittest-xml-reportingA unittest test runner that exports test…
permissive · top 5,000 on PyPI
elementpathProvides XPath 1.0, 2.0, 3.0, and 3.1 selectors…
permissive · top 5,000 on PyPI
xmlrunnerA unittest test runner that exports test…
copyleft · top 15,000 on PyPI