Reference

Output and tests

Choose between PDF, product HTML and debug HTML, and test your documents with snapshot files.

On this page

Three kinds of output

Output Command Stable? Use it for
PDF render … -o doc.pdf yes the document you send
Product HTML render … --format html yes showing the document in a web portal, and snapshot tests
Debug HTML render … --debug no finding out why a page looks wrong

Product HTML

--format html writes the finished document as HTML. Its class names are part of brevier's contract: an update adds classes but never removes or changes one. Today there is one:

Class On Meaning
brevier-page <body> The whole document. The web theme puts all its rules under this class.

Debug HTML

--debug writes .debug.html and .debug.css next to the output. They show exactly what the engine received. They can change in any release, so do not build on them.

Snapshot tests

Comparing two PDFs is hard. Comparing two HTML files is a text diff. So test the product HTML: render a fixed example and compare it with a file in your repository.

test_invoice.py
from brevier.testing import assert_matches_snapshot


def test_invoice_snapshot():
    html = render_my_invoice()  # your own code, with --format html
    assert_matches_snapshot(html, "snapshots/invoice.html")
Case Result
The HTML matches the file The test passes.
The HTML differs The test fails and shows the changed lines.
No file yet The test fails and tells you how to create it.

When a change is on purpose, write the new snapshot instead of editing the test:

BREVIER_UPDATE_SNAPSHOTS=1 pytest test_invoice.py

This writes every snapshot the run touches and never fails. Review the changed snapshot files in your diff, then run the tests again without the variable.