Skip to content

Commit 885506b

Browse files
authored
test: turn unexpected warnings into errors (#2480)
1 parent 184ad6f commit 885506b

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

pytest.ini

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,17 @@ asyncio_default_fixture_loop_scope=function
55
testpaths=tests/pytest/
66
; Note: Browsers are set within `./Makefile`
77
addopts = --strict-markers --durations=6 --durations-min=5.0 --numprocesses auto
8+
; Tests must not emit stray warnings; assert expected ones with `pytest.warns()`.
9+
; Third-party deprecations we can't act on go in the ignore list below.
10+
filterwarnings =
11+
error
12+
; narwhals calls polars' deprecated `cat.get_categories()`
13+
; https://github.com/narwhals-dev/narwhals/issues/3895
14+
ignore:`cat.get_categories\(\)` is deprecated:DeprecationWarning
15+
; Both of these are raised from finalizers at GC time (a leaked
16+
; `TemporaryDirectory`, an abandoned coroutine), so as errors they fail
17+
; whichever test happens to be running when the collector fires rather than the
18+
; test at fault -- i.e. they make the suite flaky instead of strict.
19+
ignore::ResourceWarning
20+
ignore::pytest.PytestUnraisableExceptionWarning
821
; verbosity_test_cases=2

tests/pytest/test_offcanvas.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,11 @@ def test_show_offcanvas_with_html_wraps_new_panel():
317317
"""show_offcanvas() treats htmltools.HTML() as content, not an id"""
318318
mock_session = _mock_session()
319319

320-
result_id = ui.show_offcanvas(
321-
HTML("<p>Rendered content.</p>"), session=mock_session
322-
)
320+
# An anonymous panel has no title, so it also warns about accessibility.
321+
with pytest.warns(UserWarning, match="aria-label"):
322+
result_id = ui.show_offcanvas(
323+
HTML("<p>Rendered content.</p>"), session=mock_session
324+
)
323325

324326
assert isinstance(result_id, str) and result_id != ""
325327
assert mock_session._send_message_sync.call_count == 1
@@ -333,7 +335,9 @@ def test_show_offcanvas_with_tag_wraps_new_panel():
333335
"""show_offcanvas() wraps a bare Tag into a new anonymous offcanvas"""
334336
mock_session = _mock_session()
335337

336-
result_id = ui.show_offcanvas(tags.p("Body content"), session=mock_session)
338+
# An anonymous panel has no title, so it also warns about accessibility.
339+
with pytest.warns(UserWarning, match="aria-label"):
340+
result_id = ui.show_offcanvas(tags.p("Body content"), session=mock_session)
337341

338342
assert mock_session._send_message_sync.call_count == 1
339343
message = mock_session._messages_sent[0]

tests/pytest/test_renderer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,21 @@ def bad_render(x: int) -> str:
109109
def test_download_rejects_function_with_params():
110110
with pytest.raises(TypeError, match="no required parameters"):
111111

112-
@render.download # pyright: ignore[reportArgumentType]
112+
@render.download_button # pyright: ignore[reportArgumentType]
113113
def bad_download(x: int) -> str:
114114
return str(x)
115115

116116

117117
def test_download_accepts_function_with_no_params():
118-
@render.download
118+
@render.download_button
119119
def good_download():
120120
return "file.txt"
121121

122122

123123
def test_download_warns_function_with_default_params():
124124
with pytest.warns(UserWarning, match="parameter.*with default values: x"):
125125

126-
@render.download
126+
@render.download_button
127127
def good_download(x: str = "file.txt") -> str:
128128
return x
129129

0 commit comments

Comments
 (0)