Ejemplo n.º 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__
Ejemplo n.º 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)
Ejemplo n.º 3
0
 def third_function():
     assert not is_call_from_module()
Ejemplo n.º 4
0
 def another_function():
     assert not is_call_from_module()
     third_function()
Ejemplo n.º 5
0
        def function():
            assert is_call_from_module()

            another_function()