All Questions
4 questions
1
vote
2
answers
614
views
How to Mock a Function Within a FastAPI Route Using Pytest
I'm working on a FastAPI application and am trying to write some tests for one of my routes. My testing environment cannot make calls to external services. My goal is just to test the parsing of the ...
1
vote
1
answer
1k
views
How to mock a class in one script from another test script running the first
I have a class SQLES in a separate script, sqles.py, which is imported in main.py and comprises methods to read SQL data and set the results in the class instance.
I am now writing a test script, ...
1
vote
0
answers
2k
views
Python how to patch entire object with patch.object
Python's unittest.mock built-in library provides patch.object, which let's you:
patch the named member (attribute) on an object (target) with a mock object.
With regular patch, you can easily ...
1
vote
1
answer
556
views
How to patch method io.RawIOBase.read with unittest?
I've recently learned about unittest.monkey.patch and its variants, and I'd like to use it to unit test for atomicity of a file read function. However, the patch doesn't seem to have any effect.
Here'...