skillfed

xmlunittest

Library using lxml and unittest for unit testing XML.

xmlunittest v1.0.1 1.0M downloads/30d#4,537 on PyPI16
Permissive license MIT DORMANT released

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 xmlunittest

uv

uv add xmlunittest

poetry

poetry add xmlunittest

Installing 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

Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Quality AssuranceTopic :: Software Development :: TestingTopic :: Software Development :: Testing :: UnitTopic :: Text Processing :: Markup :: XML

Tags

xml unit testingxpath assertionsxml document comparisonunittest xml validationlxml test helpersxml schema testingstructured xml testing
xml-testingxpath-assertions

More Testing packages