Description
Context
mapping.py previously had warnings.filterwarnings("ignore") at module scope (line 26), which suppressed ALL Python warnings for the entire process. This was fixed by:
- Removing the global suppression
- Adding targeted
warnings.catch_warnings()inside_load_priogrid()scoped to the CRS centroid warning only
This fix resolved C-18 (global warning suppression) and D-03 (warning suppression disagreement).
No test verifies this fix. If someone re-adds warnings.filterwarnings("ignore") to mapping.py — a common "fix" when noisy warnings appear — no test detects it. The global suppression returns, hiding geopandas deprecation warnings, shapely geometry errors, numpy overflow warnings, and all other correctness signals.
This was identified by the falsification campaign (Claim 3.3, FALSIFIED).
Why now
This is the fastest test to write (~15 minutes) and protects against the most likely regression: a developer encountering a noisy warning and adding a global filter to silence it.
Requirements
Test: test_no_global_warning_suppression
Setup:
Import warnings and views_postprocessing.unfao.mapping.mapping (the conftest intercept handles shapefile loading).
Assert:
No entry in warnings.filters has the pattern ("ignore", None, <Warning>, None, 0) — which is what warnings.filterwarnings("ignore") adds. Specifically:
import warnings
global_ignores = [
f for f in warnings.filters
if f[0] == "ignore" and f[2] is Warning
]
assert len(global_ignores) == 0, (
f"Global warning suppression detected: {global_ignores}. "
"Use targeted warnings.catch_warnings() instead."
)Test: test_centroid_crs_warning_is_suppressed
Assert:
The specific CRS centroid warning IS suppressed (targeted suppression works):
import warnings
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
# Trigger centroid calculation on geographic CRS
mapper.priogrid_gdf["geometry"].centroid
crs_warnings = [x for x in w if "geographic CRS" in str(x.message)]
# The targeted suppression in _load_priogrid catches this during loading,
# but calling .centroid again outside the suppression context should show
# the warning is NOT globally suppressed — it fires here.Actually, a simpler approach: verify that after importing mapping.py, a non-centroid warning (e.g., a UserWarning) IS visible — proving global suppression is not active.
Test: test_non_centroid_warnings_are_visible
import warnings
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
warnings.warn("test warning", UserWarning)
assert len(w) == 1, "UserWarning should be visible — global suppression must not be active"Acceptance criteria
-
test_no_global_warning_suppressionpasses -
test_non_centroid_warnings_are_visiblepasses - Re-adding
warnings.filterwarnings("ignore")to mapping.py causes at least one test to fail - Tests are in
tests/test_regression.py
References
- Falsification campaign Claim 3.3 (FALSIFIED)
- Test stub:
tests/test_falsification_campaign_3_3.py - Risk register: C-18 (resolved), D-03 (resolved)
- Cluster B fix item Development #1 (done)
Activity