When attaching extra files, the file content is kept in memory even after files are written, effectively leaking memory. Mainly relevant if --self-contained-html is not used.
extras.append(pytest_html.extras.text('some very large content'))
This is a problem when we use large attachments, for example log files. With long test suites, memory usage constantly climbs. Based on my debugging, this is caused by extras being stored on the TestReport object.
Expected behavior
References to contents are dropped after files are written, letting GC claim them. Alternatively, the API accepts file paths and copies them into assets.
Workaround
Save files yourself, in a file under the report directory. Attach to report as a relative url.
Issue
When attaching extra files, the file content is kept in memory even after files are written, effectively leaking memory. Mainly relevant if
--self-contained-html
is not used.This is a problem when we use large attachments, for example log files. With long test suites, memory usage constantly climbs. Based on my debugging, this is caused by extras being stored on the
TestReport
object.Expected behavior
References to contents are dropped after files are written, letting GC claim them. Alternatively, the API accepts file paths and copies them into assets.
Workaround
Save files yourself, in a file under the report directory. Attach to report as a relative url.
Simplified example:
This produces a nearly identical report, without the memory usage.