예제 #1
0
    def module():
        import pytest

        from pydantic.generics import is_call_from_module

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

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

        import pytest

        from pydantic.generics import is_call_from_module

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

        e = exc_info.value
        assert isinstance(e.__cause__, IndexError)
        assert isinstance(e.__context__, IndexError)
예제 #3
0
 def third_function():
     assert not is_call_from_module()
예제 #4
0
 def another_function():
     assert not is_call_from_module()
     third_function()
예제 #5
0
        def function():
            assert is_call_from_module()

            another_function()