Opened 4 years ago

Closed 4 years ago

#16921 closed New feature (fixed)

Add assertHTMLEqual and related assert methods to TestCase

Reported by: carljm Owned by: gregmuellegger
Component: Testing framework Version: master
Severity: Normal Keywords: form-rendering
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


This need came out of the form-rendering GSoC branch, due to a bunch of existing form rendering tests that test against HTML strings. Switching to template-based rendering would often cause spurious test failures due to irrelevant differences in HTML tag attribute ordering or whitespace. So in the branch we've added assertHTMLEqual and assertHTMLNotEqual methods, as well as a boolean "html" argument to assertContains.

These additions can be committed separately from the rest of the branch, but need to be split out first.

Most up-to-date code for the branch is at

Attachments (1)

16921-assertHTMLEqual.1.diff (32.8 KB) - added by gregmuellegger 4 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 4 years ago by carljm

The Python standard library HTMLParser bug described here and here is an issue that needs to be resolved before this patch is ready for trunk. One possible workaround is demonstrated here.

comment:2 Changed 4 years ago by gregmuellegger

  • Owner changed from nobody to gregmuellegger
  • Status changed from new to assigned

The mentioned bug is fixed. Attached is a patch with the feature including tests and documentation.
It would be nice if someone could especially review the english texts in docs and release notes.

I consider the code itself as pretty stable since it's already used in my gsoc form-rendering branch.

Here is a link to my branch of this bug:

And the compare view:

comment:3 Changed 4 years ago by gregmuellegger

Next step now is to eat our own dog food and using this feature were suitable in django's test-suite.

Most of the work is already done in my soc2011/form-rendering branch, but needs a bit of work to extract it:

comment:4 Changed 4 years ago by claudep

  • Has patch unset
  • Patch needs improvement unset

Thanks, but it would still be welcome to attach a diff version of your work to this ticket.

Changed 4 years ago by gregmuellegger

comment:5 Changed 4 years ago by gregmuellegger

oops, I prepared it but forgot to attach it. Here it is.

comment:6 Changed 4 years ago by gregmuellegger

I copied over my work from the gsoc branch to use the new assertions where suiteable in django's test suite. Unfortunatelly, the patch is with >350kb too big for trac. It rejects the upload.

You can download the current status via github:

Last edited 4 years ago by gregmuellegger (previous) (diff)

comment:8 Changed 4 years ago by claudep

  • Has patch set

comment:9 Changed 4 years ago by carljm

  • Resolution set to fixed
  • Status changed from assigned to closed

In [17414]:

Fixed #16921 -- Added assertHTMLEqual and assertHTMLNotEqual assertions, and converted Django tests to use them where appropriate. Thanks Greg Müllegger.

Note: See TracTickets for help on using tickets.
Back to Top