[TIP] How to return fake values of function called from source file?

Rocky Ji rockyji3438 at gmail.com
Sat Sep 21 21:44:17 PDT 2019


Hi all,

New here, new to testing. I have to refactor a friends python code.

It uses pyodbc to work (read only) on SQL server. I do not have admin
rights on my computer, so I want to:

 1. Intercept calls made to pyodbc's cursor.execute(), and return fictional
data **based** on the string argument passed (I have already written a
module that can generate random text/blobs as demanded) (the arg is always
`select` statment)
 2. Fool pyodbc into thinking that it did connect SQL Server.

How do I accomplish this? I read many docs & I can write simple test I but
don't understand how to use pytest.monkeypatch or unittest.mock to
accomplish either 1 or 2.

Please guide.

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20190922/4a0ad7eb/attachment.html>


More information about the testing-in-python mailing list