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

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

How To Mock A Boto3 Client Object/call

I'm trying to mock one particular boto3 function. My module, Cleanup, imports boto3. Cleanup … Read more How To Mock A Boto3 Client Object/call

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

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__?

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

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`

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

Mocking Default=timezone.now For Unit Tests

I'm trying to write unit tests for a django app that does a lot of datetime operations. I have… Read more Mocking Default=timezone.now For Unit Tests

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?

Integrating Mock And Patch In A Python Unit Test

I have a class with a few methods that I am writing unit test cases for. For minimum reproducible e… Read more Integrating Mock And Patch In A Python Unit Test

Running Pytest Tests Against Multiple Backends?

I've built a series of tests (using pytest) for a codebase interacting with the Github API (bot… Read more Running Pytest Tests Against Multiple Backends?

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

How To Unit Test Time Based Functions Without Adding Parameters

I created a function that returns seconds left until the next occurrence of that time, but I came a… Read more How To Unit Test Time Based Functions Without Adding Parameters

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?

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?

Mocking Methods On An Instance Variable In Python

I'm trying to figure out how to properly Mock an instance variable which is an instance of anot… Read more Mocking Methods On An Instance Variable In Python

Mock Exception With Side Effect Raised In Class Method And Caught In Calling Method Gives 'did Not Raise'

Using side_effect, I am trying to raise an exception when a mock is called but I get a DID NOT RAIS… Read more Mock Exception With Side Effect Raised In Class Method And Caught In Calling Method Gives 'did Not Raise'

Mock.patch And Multiprocessing

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

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`