Skip to content

Commit d82d401

Browse files
committed
Uploading current code for some discussion
1 parent 921482f commit d82d401

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

tests/unit/test_json.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,18 @@ def cleanup_json_module_for_reload():
247247
pa.register_extension_type(db_dtypes.json.JSONArrowType())
248248
except pa.ArrowKeyError:
249249
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.")
252250

253251
# 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
255253
del sys.modules[json_module_name]
256254

257255
yield # Run the test that uses this fixture
258256

259257
# Cleanup: Put the original module back if it existed
260258
# This helps isolate from other tests that might import db_dtypes.json
261-
if original_module:
259+
if original_module: # COVERAGE FAIL: 259-261
262260
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
264262
# If the test re-imported it but it wasn't there originally, remove it
265263
del sys.modules[json_module_name]
266264

@@ -274,21 +272,21 @@ def test_json_arrow_type_reregistration_is_handled(cleanup_json_module_for_reloa
274272
is caught by the except block and does not raise an error.
275273
"""
276274

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
277280
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.
281281
import db_dtypes.json # noqa: F401
282282

283283
assert (
284284
True
285285
), "Module re-import completed without error, except block likely worked."
286286

287-
except pa.ArrowKeyError:
287+
except pa.ArrowKeyError: # COVERAGE FAIL: 287-294
288288
# If this exception escapes, the except block in db_dtypes/json.py failed.
289289
pytest.fail(
290290
"pa.ArrowKeyError was raised during module reload, "
291291
"indicating the except block failed."
292292
)
293-
except Exception as e:
294-
pytest.fail(f"An unexpected exception occurred during module reload: {e}")

0 commit comments

Comments
 (0)