Skip to content

Commit 730a0e3

Browse files
author
Fabien Coelho
committed
add a call counter
1 parent c47ec47 commit 730a0e3

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

FlaskTester.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ class Client:
315315
AuthHook = Callable[[Any, str, str|None], None] # type: ignore
316316

317317
def __init__(self, auth: Authenticator, default_login: str|None = None):
318+
self._calls = 0
318319
self._auth = auth
319320
self._cookies: dict[str, dict[str, str]] = {} # login -> name -> value
320321
self._default_login = default_login
@@ -357,6 +358,8 @@ def request(self, method: str, path: str, status: int|None = None, content: str|
357358
:param **kwargs: More request parameters (headers, data, json…).
358359
"""
359360

361+
self._calls += 1
362+
360363
if "login" in kwargs:
361364
login = kwargs["login"]
362365
del kwargs["login"]
@@ -448,6 +451,12 @@ def delete(self, path: str, status: int|None = None, content: str|None = None, *
448451
"""HTTP DELETE request, see `Client.request`."""
449452
return self.request("DELETE", path, status=status, content=content, **kwargs)
450453

454+
def __str__(self):
455+
return f"client calls: {self._calls}"
456+
457+
def __del__(self):
458+
log.info(f"ending, {self}")
459+
451460

452461
class RequestClient(Client):
453462
"""Request-based test provider.

docs/versions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ please report any [issues](https://github.com/zx80/flask-tester/issues).
1313
- activate _Pypy 3.11_ and _Python 3.14_ in GitHub CI.
1414
- mkdocs? docsify?
1515

16+
## ? on ?
17+
18+
- count api calls internally, and show an info at the end
19+
1620
## 5.1 on 2025-11-22
1721

1822
- use SPDX licensing format.

0 commit comments

Comments
 (0)