Is it possible to test cffi module with mock?

63 views
Skip to first unread message

Yu Yang

unread,
Sep 6, 2017, 5:48:48 AM9/6/17
to python-cffi
I want to check if the arguments passed to c functions are correct, so I use mock to patch these c function, but python reports error 
AttributeError: cannot write to function or constant

Any idea to solve this problem? thx

Armin Rigo

unread,
Sep 8, 2017, 4:05:12 AM9/8/17
to pytho...@googlegroups.com
Hi Yu,
Indeed, the ``lib`` object is mostly read-only. Maybe you need to
replace the ``lib`` object itself with a mock, so that when the code
calls ``lib.yourfunc(42)`` it will actually call a method on your mock
object.


A bientôt,

Armin.
Reply all
Reply to author
Forward
0 new messages