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

Really Weird... Can't Set Attributes Of Built-in/extension Type 'lxml.etree._element'

I've changed attributes for other classes before without issues. _Element is obviously not a bu… Read more Really Weird... Can't Set Attributes Of Built-in/extension Type 'lxml.etree._element'

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

How Do I Test An Api Client With Python?

I'm working on a client library for a popular API. Currently, all of my unit tests of said clie… Read more How Do I Test An Api Client With Python?

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 Instance Attributes

Please help me understand why the following doesn't work. In particular - instance attributes o… Read more Mocking Instance Attributes

Python Propertymock Side Effect With Attributeerror And Valueerror

I am trying to mock a property of a class (@property decorator) and have bumped into this incorrect… Read more Python Propertymock Side Effect With Attributeerror And Valueerror

Isinstance And Mocking

class HelloWorld(object): def say_it(self): return 'Hello I am Hello World' de… Read more Isinstance And Mocking

Adding Mock Objects In Python

My code under test does sth like this: def to_be_tested(x): return round((x.a + x.b).c()) I woul… Read more Adding Mock Objects In Python

How Do I Patch A Sys Attribute Using A Decorator?

I have a function which depends on the Python version. I would like to test this in a unittest by m… Read more How Do I Patch A Sys Attribute Using A Decorator?

How To Mock Using Patch Relative Paths?

I have something like this in a python test file: from mock import patch, from ..monkey import ook … Read more How To Mock Using Patch Relative Paths?

Python Http Post Method Returns Response As Magicmock Object Instead Of Value

I am trying to check the response status code after trigerring some API with a POST method, Respons… Read more Python Http Post Method Returns Response As Magicmock Object Instead Of Value

Python3 Mock Doesn't Work For All Paths

The Production file (production_file.py) is: class MyError(Exception): pass class MyClass: … Read more Python3 Mock Doesn't Work For All Paths

Mocking File Objects Or Iterables In Python

Which way is proper for mocking and testing code that iters object returned by open(), using mock l… Read more Mocking File Objects Or Iterables In Python

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

Python Patch Object With A Side_effect

I'm trying to have a Mock object return certain values based on the input given. I looked up a … Read more Python Patch Object With A Side_effect

Mock A Class With Tedious __init__

I have a class that actually connects to a service and does authentication and stuff, but all of th… Read more Mock A Class With Tedious __init__

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.patch And Multiprocessing

I'm struggling to use mock.patch in a multiprocessing environment while without multiprocessing… Read more Mock.patch And Multiprocessing