Skip to content

How to use mock.assert_called_with inside tests properly, when we have datetime attribute #698

Answered by Lancetnik
rjambrecic asked this question in Q&A
Discussion options

You must be logged in to vote

@rjambrecic mock body designed to represent inner broker json message, not python serialized one
So, to test it you need to make your pydantic object JSONable

As an example - here is an app

from datetime import datetime
from pydantic import BaseModel
from faststream.rabbit import RabbitBroker, TestRabbitBroker

broker = RabbitBroker()

class Date(BaseModel):
    time: datetime

@broker.subscriber("in")
async def rabbit_handler(msg: Date):
    pass

To test it we can make our object JSONable

import pytest
from pydantic_core import to_jsonable_python
# or (for PydanticV1 and PydanticV2)
# from faststream._compat import model_to_jsonable

@pytest.mark.asyncio
async def test_pub():
    async with

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rjambrecic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants