Skip to content

Commit

Permalink
Make qt.machinery.Unavailable inherit ModuleNotFoundError
Browse files Browse the repository at this point in the history
With pytest 8.2, pytest.importorskip(...) now only considers ModuleNotFoundError
rather than all ImportErrors, and warns otherwise:
pytest-dev/pytest#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).
  • Loading branch information
The-Compiler committed Apr 30, 2024
1 parent 4fdc32f commit 3d96fc2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion qutebrowser/qt/machinery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_qt_machinery.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 3d96fc2

Please sign in to comment.