Coverage for Users/vladimirpavlov/PycharmProjects/parameterizable/tests/test_version_fallback.py: 100%

1 import importlib

2 import types

3

4 import pytest

5

6

7 def test_version_fallback_to_unknown(monkeypatch):

8 # Patch importlib.metadata.version to raise PackageNotFoundError

9 import importlib.metadata as md

10

11 def _raise(_name):

12 raise md.PackageNotFoundError

13

14 monkeypatch.setattr(md, "version", _raise, raising=True)

15

16 # Reload the _version_info module first, then the package to execute with patched metadata.version

17 import mixinforge._version_info

18 import mixinforge

19 importlib.reload(mixinforge._version_info)

20 parameterizable = importlib.reload(mixinforge)

21

22 assert hasattr(parameterizable, "__version__")

23 assert parameterizable.__version__ == "unknown"

24

25 # Reload again after monkeypatch auto-reverts, to restore normal behavior

26 importlib.reload(mixinforge._version_info)

27 parameterizable = importlib.reload(parameterizable)

28 assert isinstance(parameterizable.__version__, str)