Skip to content Skip to sidebar Skip to footer
Showing posts with the label Mocking

Writing A Contextmanager That Patches An Object

In my Python 3 test code, I have a lot of these statements: from unittest.mock import patch user =… Read more Writing A Contextmanager That Patches An Object

Mock A Pyqt Method

I have an existing class which inherits from the PyQT5 classes QWidget and Ui_Dialog. I want to use… Read more Mock A Pyqt Method

Mock Open() Function Used In A Class Method

I tried to mock the open function used in a method of my class. I found this thread How do I mock a… Read more Mock Open() Function Used In A Class Method

How To Patch The Python 3 Breakpoint() Builtin?

I wrote a decorator that halts my program with breakpoint() if a critical error happens. def the_br… Read more How To Patch The Python 3 Breakpoint() Builtin?

Mocking Render To Response With Pyramid

I have a decorator that looks like so: def validate_something(func): def validate_s(request): … Read more Mocking Render To Response With Pyramid

How To Mock Python's Datetime.now() In A Class Method For Unit Testing?

I'm trying to write tests for a class that has methods like: import datetime import pytz class… Read more How To Mock Python's Datetime.now() In A Class Method For Unit Testing?

Max Recursion Depth While Trying To Mock Instance Method

I want to mock an instance method. First I want to modify the arguments and then I want to call the… Read more Max Recursion Depth While Trying To Mock Instance Method

Making A Wrapper For `mock.patch`

Some customized patches from mock.patch I want to use over and over without littering my test code … Read more Making A Wrapper For `mock.patch`