From b6e5375576f2de534947e327cd2cffe3a08388b8 Mon Sep 17 00:00:00 2001 From: Bruno Voisin Date: Mon, 6 Oct 2025 11:27:27 +0200 Subject: [PATCH] fix: resolve perf issue with a lot of forms The property `response.forms` takes time (about 1.6 seconds) on an HTML response containing a lot of froms (more than 30). For each form, the whole reponse is parsed. To avoid reparsing all the HTML, I added a cache on the property `Response.html` that parse the response. --- webtest/response.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webtest/response.py b/webtest/response.py index 8498339..98609b5 100644 --- a/webtest/response.py +++ b/webtest/response.py @@ -1,3 +1,4 @@ +from functools import cached_property import re from webtest import forms @@ -385,7 +386,7 @@ def __repr__(self): location = '' return ('<' + self.status + ct + location + body + '>') - @property + @cached_property def html(self): """ Returns the response as a `BeautifulSoup