From c380a57e22cce5e485f7ffd0548f174c4deec2eb Mon Sep 17 00:00:00 2001 From: Rob Svirskas Date: Wed, 7 Oct 2026 12:25:07 -0400 Subject: [PATCH] fix(tests): stub pymongo so the suite collects without a driver installed tests/test_name_maintenance.py imports fix_middle_names, which imports pymongo. CI installs pytest, jrc_common and doi_common only, so collection failed outright: ERROR collecting tests/test_name_maintenance.py ModuleNotFoundError: No module named 'pymongo' That took the whole suite down, not just the new file - a collection error is fatal, so the 94 pre-existing tests never ran either. Both interpreters have been failing since the maintenance programs landed. The stub carries a real exception class rather than a bare module. Both maintenance programs catch pymongo.errors.PyMongoError, and an except clause naming something that is not an exception class raises TypeError when it is reached - which would turn a database error into a confusing failure three frames from its cause. Nothing here exercises that path today, so the mistake would have sat unnoticed until it mattered. Verified in a virtual environment built to match the workflow exactly - pytest plus the two git-installed libraries, no pymongo, no tqdm, no jrc_email. 113 tests pass there, and the stub is confirmed to be the module actually in use. Co-Authored-By: Claude Opus 5 (1M context) --- tests/conftest.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index eb1312d7..002f3c72 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -64,6 +64,11 @@ def _prepare_imports(): _ensure(name) _ensure('unidecode', unidecode=lambda s: s) _ensure('tqdm', tqdm=lambda x, **kw: x) + # The maintenance programs catch pymongo.errors.PyMongoError. The stub has + # to carry a real exception class: an except clause naming something that is + # not one raises TypeError when it is reached, which would turn a database + # error into a confusing failure three frames away from its cause. + _ensure('pymongo', errors=types.SimpleNamespace(PyMongoError=Exception)) for pkg, sub in (('jrc_common', 'jrc_common'), ('jrc_email', 'jrc_email'), ('doi_common', 'doi_common')): dotted = f'{pkg}.{sub}'