Closed vik748 closed 7 months ago
I haven't tried this yet. Is there anything special about this library in this regard? Can't you create the mock object from within your tet case as usual? Or even use @patch
?
The main challenge I ran into is that when we use the decorator from ros2-easy-test, inside the function the node being tested is already created, so I was not able to modify any return values. I was able to work around it by using a Pytest fixture and performing all the mocking in there. How would you approach this?
I was able to work around it by using a Pytest fixture and performing all the mocking in there.
That sounds reasonable and like the way to go. I would have tried the same. Do you think this is bad in some significant way? Should we add an example for how to do this to the library?
I wouldn't say it is bad, it was my first time using pytest so there was an additional layer of uncertainty. It would definitely be helpful to have some examples.
Is your use case suitable as a demo? We could think about adding something simple here: tests/demo
.
Let's close this until there is a concrete proposal for what to do.
Hi, Do you have an example for using ros2_easy_test along with mock. We have a Node which reads from the sensors using the socket library and I'd like to mock either the socket.socket OR the lower level library which uses socket.socket, so that I can fake a read from the sensor and check for published messages.
Thanks in advance for your help.