Beispiel #1
0
    def module():
        import pytest

        from pydantic.generics import get_caller_module_name

        with pytest.raises(
                RuntimeError,
                match='This function must be used inside another function'
        ) as exc_info:
            get_caller_module_name()

        e = exc_info.value
        assert isinstance(e.__cause__, IndexError), e.__cause__
        assert isinstance(e.__context__, IndexError), e.__context__
Beispiel #2
0
    def module():
        from unittest.mock import patch

        import pytest

        from pydantic.generics import get_caller_module_name

        with pytest.raises(
                RuntimeError,
                match='This function must be used inside another function'
        ) as exc_info:
            with patch('inspect.stack', new=lambda: [..., ...]):
                get_caller_module_name()

        e = exc_info.value
        assert isinstance(e.__cause__, IndexError)
        assert isinstance(e.__context__, IndexError)
Beispiel #3
0
def test_get_caller_module_name_not_found(mocker):
    mocker.patch('inspect.getmodule', return_value=None)
    assert get_caller_module_name() is None
Beispiel #4
0
 def get_current_module_name():
     return get_caller_module_name()