π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
tests: strict no-warnings gate on kornia import (#3894)
Dmytro Mishkin1f571e286265
diff --git a/tests/test_import.py b/tests/test_import.pyindex 5cc435b0d..52692264c 100644--- a/tests/test_import.py+++ b/tests/test_import.py@@ -49,5 +49,43 @@ def test_import_without_jit_script_deprecation():capture_output=True,text=True,check=False,+ timeout=300,)assert result.returncode == 0, f"importing kornia raised a deprecation warning:\n{result.stderr}"+++def test_import_emits_no_warnings():+ """Importing kornia must not emit ANY warning, whatever module raises it.++ Stricter companion to the jit-script guard above: torch is imported first so its own+ import-time warnings (outside kornia's control, and version-dependent) are excluded,+ then every warning is promoted to an error for the kornia import itself. This is the+ honest form of the ``python -W error -c "import kornia"`` gate from+ https://github.com/kornia/kornia/issues/3727 β it fails on any warning kornia's import+ path emits or triggers, protecting downstream users who run with ``-W error``.++ ``resetwarnings`` first, so filters inherited from the environment (``PYTHONWARNINGS``,+ a ``-W`` flag propagated by the test runner) cannot make the torch import fail and+ cannot pre-arm filters that fight the ``simplefilter("error")`` below.+ """+ script = textwrap.dedent(+ """+ import warnings++ warnings.resetwarnings()++ import torch # noqa: F401 # torch's own import warnings are not kornia's to fix++ warnings.simplefilter("error")+ import kornia # noqa: F401+ """+ )+ # Same trusted, fixed command shape as above.+ result = subprocess.run( # noqa: S603+ [sys.executable, "-c", script],+ capture_output=True,+ text=True,+ check=False,+ timeout=300,+ )+ assert result.returncode == 0, f"importing kornia emitted a warning:\n{result.stderr}"