Top "Python-mock" questions

A test utility that patches objects with user-defined code or data.

Python mock multiple return values

I am using pythons mock.patch and would like to change the return value for each call. Here is the …

python unit-testing mocking python-mock
Mocking a function to raise an Exception to test an except block

I have a function (foo) which calls another function (bar). If invoking bar() raises an HttpError, I want to handle …

python unit-testing python-2.7 mocking python-mock
Assert a function/method was not called using Mock

I'm using the Mock library to test my application, but I want to assert that some function was not called. …

python unit-testing mocking python-mock
Python Mocking a function from an imported module

I want to understand how to @patch a function from an imported module. This is where I am so far. …

python unit-testing python-unittest python-mock
Mock attributes in Python mock?

I'm having a fairly difficult time using mock in Python: def method_under_test(): r = requests.post("http://localhost/post") …

python unit-testing testing mocking python-mock
Better way to mock class attribute in python unit test

I have a base class that defines a class attribute and some child classes that depend on it, e.g. …

python unit-testing mocking python-mock
Python Mock object with method called multiple times

I have a class that I'm testing which has as a dependency another class (an instance of which gets passed …

python unit-testing mocking python-mock
How do I mock part of a python constructor just for testing?

I am new to Python, so I apologize if this is a duplicate or overly simple question. I have written …

python unit-testing mocking python-mock
How do you mock patch a python class and get a new Mock object for each instantiation?

OK, I know this is mentioned in the manual, and probably has to do with side_effect and/or return_…

python mocking python-unittest python-mock
python mock assert_called_with

I'm trying to understand the assert_called_with within mock but the code I wrote throws some error. import os …

python python-unittest python-mock python-unittest.mock