Exemple #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__
Exemple #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)
Exemple #3
0
 def third_function():
     assert not is_call_from_module()
Exemple #4
0
 def another_function():
     assert not is_call_from_module()
     third_function()
Exemple #5
0
        def function():
            assert is_call_from_module()

            another_function()