Skip to content

Instantly share code, notes, and snippets.

@vahedq
Last active June 11, 2018 21:53
Show Gist options
  • Save vahedq/9bf15f121b28aa7f1c57e382bfea3ab8 to your computer and use it in GitHub Desktop.
Save vahedq/9bf15f121b28aa7f1c57e382bfea3ab8 to your computer and use it in GitHub Desktop.
Django TestCase for XML comparison
from django.test import TestCase
from doctest import Example
from lxml.doctestcompare import LXMLOutputChecker
class XmlTestCase(TestCase):
def assertXmlEqual(self, got, want):
checker = LXMLOutputChecker()
if not checker.check_output(want, got, 0):
message = checker.output_difference(Example('', want), got, 0)
raise AssertionError(message)
# Then use it like this in your django test module.
class MyTextModule(XmlTestCase):
def test(self):
self.assertXmlEqual(xml_str_1, xml_str_2)
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment