Show correct query timings, closes #2446

This commit is contained in:
Simon Willison 2026-09-16 21:23:54 -07:00
commit 9cdf95ac2c
2 changed files with 20 additions and 1 deletions

View file

@ -1,5 +1,6 @@
import pathlib
import urllib.parse
from types import SimpleNamespace
import pytest
from bs4 import BeautifulSoup as Soup
@ -72,6 +73,21 @@ DEFAULT_EXPRESSION_OPTIONS = [
]
@pytest.mark.asyncio
@pytest.mark.parametrize("table", ("simple_primary_key", "simple_view"))
@pytest.mark.parametrize("duration", (0.125, 0.25))
async def test_table_footer_query_ms(ds_client, monkeypatch, table, duration):
times = iter((10.0, 10.0 + duration))
# Only mock the table view's clock, leaving SQL time limits unaffected.
monkeypatch.setattr(
"datasette.views.table.time", SimpleNamespace(perf_counter=lambda: next(times))
)
response = await ds_client.get(f"/fixtures/{table}")
assert response.status_code == 200
footer = Soup(response.text, "html.parser").find("footer")
assert f"Queries took {duration * 1000}ms" in footer.get_text()
@pytest.mark.asyncio
@pytest.mark.parametrize(
"path,expected_definition_sql",