From 3d96fc2656b372474c4f302617333bf2bb3e9cde Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 30 Apr 2024 19:24:25 +0200 Subject: Make qt.machinery.Unavailable inherit ModuleNotFoundError With pytest 8.2, pytest.importorskip(...) now only considers ModuleNotFoundError rather than all ImportErrors, and warns otherwise: https://github.com/pytest-dev/pytest/pull/12220 While we could override this via pytest.importorskip(..., exc_type=machinery.Unavailable) this is a simpler solution, and it also makes more sense semantically: We only raise Unavailable when an import is being done that would otherwise result in a ModuleNotFoundError anyways (e.g. trying to import QtWebKit on Qt 6). --- qutebrowser/qt/machinery.py | 2 +- tests/unit/test_qt_machinery.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/qutebrowser/qt/machinery.py b/qutebrowser/qt/machinery.py index 9f45dd6ce..45a1f6598 100644 --- a/qutebrowser/qt/machinery.py +++ b/qutebrowser/qt/machinery.py @@ -48,7 +48,7 @@ class Error(Exception): """Base class for all exceptions in this module.""" -class Unavailable(Error, ImportError): +class Unavailable(Error, ModuleNotFoundError): """Raised when a module is unavailable with the given wrapper.""" diff --git a/tests/unit/test_qt_machinery.py b/tests/unit/test_qt_machinery.py index 25fc83ffd..cf7990393 100644 --- a/tests/unit/test_qt_machinery.py +++ b/tests/unit/test_qt_machinery.py @@ -9,7 +9,7 @@ import sys import html import argparse import typing -from typing import Any, Optional, List, Dict, Union +from typing import Any, Optional, List, Dict, Union, Type import dataclasses import pytest @@ -45,14 +45,14 @@ def undo_init(monkeypatch: pytest.MonkeyPatch) -> None: @pytest.mark.parametrize( - "exception", + "exception, base", [ - machinery.Unavailable(), - machinery.NoWrapperAvailableError(machinery.SelectionInfo()), + (machinery.Unavailable(), ModuleNotFoundError), + (machinery.NoWrapperAvailableError(machinery.SelectionInfo()), ImportError), ], ) -def test_importerror_exceptions(exception: Exception): - with pytest.raises(ImportError): +def test_importerror_exceptions(exception: Exception, base: Type[Exception]): + with pytest.raises(base): raise exception -- cgit v1.2.3-54-g00ecf