[Python] Python Compare MagicMock.__int__

Discussão em 'Python' iniciado por Stack, Agosto 25, 2025.

  1. Stack

    Stack Membro Participativo

    I am learning about using MagicMock and pytest for test python function and I found case that I have to convert MagicMock to Int and then compare to number again

    I have function do something like this

    def func(x):
    if int(x) > 5 :
    return True
    else :
    return False


    and I want to test this function so I do this

    def test_func():
    int_mock = MagicMock()
    int_mock.__gt__.return_value = True
    input_mock = MagicMock()
    input_mock.__int__.return_value = int_mock
    assert func()


    but problem is int must return int

    So how to test it it correct way

    I want to test this without assume any number like 6 or 0 for make my test pass

    Continue reading...

Compartilhe esta Página