From 41fb5225bc6382c0ec3d03482d971124b327864d Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 23 Nov 2025 10:06:45 -0800 Subject: [PATCH] Split test to filter out pytest.PytestUnraisableExceptionWarning --- tests/test_recipes.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/tests/test_recipes.py b/tests/test_recipes.py index eca3987..a7c7ef7 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -62,26 +62,37 @@ def test_dayfirst_yearfirst(fresh_db, recipe, kwargs, expected): ] +@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning") @pytest.mark.parametrize("fn", ("parsedate", "parsedatetime")) -@pytest.mark.parametrize("errors", (None, recipes.SET_NULL, recipes.IGNORE)) -def test_dateparse_errors(fresh_db, fn, errors): +def test_dateparse_errors_raises(fresh_db, fn): + """Test that invalid dates raise errors when errors=None""" fresh_db["example"].insert_all( [ {"id": 1, "dt": "invalid"}, ], pk="id", ) - if errors is None: - # Should raise an error - with pytest.raises(sqlite3.OperationalError): - fresh_db["example"].convert("dt", lambda value: getattr(recipes, fn)(value)) - else: - fresh_db["example"].convert( - "dt", lambda value: getattr(recipes, fn)(value, errors=errors) - ) - rows = list(fresh_db["example"].rows) - expected = [{"id": 1, "dt": None if errors is recipes.SET_NULL else "invalid"}] - assert rows == expected + # Exception in SQLite callback surfaces as OperationalError + with pytest.raises(sqlite3.OperationalError): + fresh_db["example"].convert("dt", lambda value: getattr(recipes, fn)(value)) + + +@pytest.mark.parametrize("fn", ("parsedate", "parsedatetime")) +@pytest.mark.parametrize("errors", (recipes.SET_NULL, recipes.IGNORE)) +def test_dateparse_errors_handled(fresh_db, fn, errors): + """Test error handling modes for invalid dates""" + fresh_db["example"].insert_all( + [ + {"id": 1, "dt": "invalid"}, + ], + pk="id", + ) + fresh_db["example"].convert( + "dt", lambda value: getattr(recipes, fn)(value, errors=errors) + ) + rows = list(fresh_db["example"].rows) + expected = [{"id": 1, "dt": None if errors is recipes.SET_NULL else "invalid"}] + assert rows == expected @pytest.mark.parametrize("delimiter", [None, ";", "-"])