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

How To Mock A Socket Object Via The Mock Library

How to mock a TCPSocket wrapper for the socket from the Python's standard libary via the mock l… Read more How To Mock A Socket Object Via The Mock Library

How To Permanently Mock Return Value Of A Function In Python Unittest

I have a function # foo.py NUM_SHARDS = 10 def get_shard(shard_key: int) -> int return (shar… Read more How To Permanently Mock Return Value Of A Function In Python Unittest

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

How Can I Mock Any Function Which Is Not Being Called Directly?

TL;DR How can I patch or mock 'any functions that are not being called/used directly'? Scen… Read more How Can I Mock Any Function Which Is Not Being Called Directly?

Why Does Mocking 'open' And Returning A Filenotfounderror Raise Attributeerror: __exit__?

Testing by mocking open with a FileNotFoundError raises AttributeError: __exit__. Why is this happe… Read more Why Does Mocking 'open' And Returning A Filenotfounderror Raise Attributeerror: __exit__?

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

Does Someone Have An Example Of Unit-testing A Soap Api With Python Zeep And Mock?

I'm building a Python app that accesses a 3rd party SOAP API with Python-zeep. I want to implem… Read more Does Someone Have An Example Of Unit-testing A Soap Api With Python Zeep And Mock?

Patch Not Mocking A Module

I'm trying to mock subprocess.Popen. When I run the following code however, the mock is complet… Read more Patch Not Mocking A Module

Python Mock Library - Patching Classes While Unit Testing

I cannot understand how mock patch works and if does it able to solve my problem. I have 3 files: c… Read more Python Mock Library - Patching Classes While Unit Testing

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

Using Python's Mock Patch.object To Change The Return Value Of A Method Called Within Another Method

Is it possible to mock a return value of a function called within another function I am trying to t… Read more Using Python's Mock Patch.object To Change The Return Value Of A Method Called Within Another Method

Python 3 - Unittest With Multiple Inputs And Print Statement Using Mocking

I'm studying Python and a few weeks ago I had created a game which the user needs to guess the … Read more Python 3 - Unittest With Multiple Inputs And Print Statement Using Mocking

Pytest - Patched Method Of A Class Does Not Return The Mock Value

My code is fairly simple but i don't understand what is going on : class MyDb : def some_fun… Read more Pytest - Patched Method Of A Class Does Not Return The Mock Value

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