Mockar timedelta within a method

0

How do I mock the return of the timedelta method being used within a method of a class? I tried it as follows;

with patch.object(datetime, 'timedelta') as mock_time:
    mock_time.return_value = (0, 1) # 1 second
    # timedelta(seconds=99) é (0, 1)
    result = meu_metodo()

Within my method I have:

async def meu_metodo(token: TokenModel):
    try:
        # timedelta(seconds=99) é (0, 99)
        now = datetime.now()
        payload = {
            'exp': now + timedelta(seconds=settings.TOKEN_EXPIRES),
            'iat': now,
            'sub': token.owner,
        }
    # ...
When I put pdb inside encode_token and I run timedelta(seconds=99) the value returned is (0, 99) when in fact it should be (0, 1) due to mock, how do I mock that timedelta within method of my class?

    
asked by anonymous 23.11.2018 / 12:26

0 answers