@@ -247,20 +247,18 @@ def cleanup_json_module_for_reload():
247
247
pa .register_extension_type (db_dtypes .json .JSONArrowType ())
248
248
except pa .ArrowKeyError :
249
249
pass # Already registered is the state we want before the test runs
250
- except ImportError :
251
- pytest .skip ("Could not import db_dtypes.json to set up test." )
252
250
253
251
# Remove the module from sys.modules so importlib.reload re-executes it
254
- if json_module_name in sys .modules :
252
+ if json_module_name in sys .modules : # COVERAGE FAIL: 252->255
255
253
del sys .modules [json_module_name ]
256
254
257
255
yield # Run the test that uses this fixture
258
256
259
257
# Cleanup: Put the original module back if it existed
260
258
# This helps isolate from other tests that might import db_dtypes.json
261
- if original_module :
259
+ if original_module : # COVERAGE FAIL: 259-261
262
260
sys .modules [json_module_name ] = original_module
263
- elif json_module_name in sys .modules :
261
+ elif json_module_name in sys .modules : # COVERAGE FAIL: 261->exit
264
262
# If the test re-imported it but it wasn't there originally, remove it
265
263
del sys .modules [json_module_name ]
266
264
@@ -274,21 +272,21 @@ def test_json_arrow_type_reregistration_is_handled(cleanup_json_module_for_reloa
274
272
is caught by the except block and does not raise an error.
275
273
"""
276
274
275
+ # Re-importing the module after the fixture removed it from sys.modules
276
+ # forces Python to execute the module's top-level code again.
277
+ # This includes the pa.register_extension_type call.
278
+
279
+ assert "db_dtypes.json" not in sys .modules
277
280
try :
278
- # Re-importing the module after the fixture removed it from sys.modules
279
- # forces Python to execute the module's top-level code again.
280
- # This includes the pa.register_extension_type call.
281
281
import db_dtypes .json # noqa: F401
282
282
283
283
assert (
284
284
True
285
285
), "Module re-import completed without error, except block likely worked."
286
286
287
- except pa .ArrowKeyError :
287
+ except pa .ArrowKeyError : # COVERAGE FAIL: 287-294
288
288
# If this exception escapes, the except block in db_dtypes/json.py failed.
289
289
pytest .fail (
290
290
"pa.ArrowKeyError was raised during module reload, "
291
291
"indicating the except block failed."
292
292
)
293
- except Exception as e :
294
- pytest .fail (f"An unexpected exception occurred during module reload: { e } " )
0 commit comments