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

How Should I Verify A Log Message When Testing Python Code Under Nose?

I'm trying to write a simple unit test that will verify that, under a certain condition, a clas… Read more How Should I Verify A Log Message When Testing Python Code Under Nose?

Mocking Grpc Status Code ('rpcerror' Object Has No Attribute 'code') In Flask App

I have to create a unittest that should mock a specific grpc status code (in my case I need NOT_FOU… Read more Mocking Grpc Status Code ('rpcerror' Object Has No Attribute 'code') In Flask App

How To Mock Session In Python's Request Library?

I have been trying to figure out how exactly to mock the session of Python's request library bu… Read more How To Mock Session In Python's Request Library?

Mock.patch And Multiprocessing

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

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

Python Mock Not Asserting Calls

I'm using the mock library to patch a class in a program that connects to a external resource a… Read more Python Mock Not Asserting Calls

Mocking Python Class In Unit Test And Verifying An Instance

I'm trying to unit test an SFTP helper class that makes some calls to the pysftp module. I want… Read more Mocking Python Class In Unit Test And Verifying An Instance

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

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

Mocked Unit Test Raises A "stop Called On Unstarted Patcher" Error

When running the test bellow, I got a stop called on unstarted patcher. def test_get_subvention_int… Read more Mocked Unit Test Raises A "stop Called On Unstarted Patcher" Error

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

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?

How To Mock Google Cloud Storage Bucket And Link It To Client Object?

I have a function in cloud run and trying to test using mock in Python. How can I mock bucket with … Read more How To Mock Google Cloud Storage Bucket And Link It To Client Object?

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

How Do I Test That I'm Calling Pickle.dump() Correctly?

I want to test this method: class Data(object): def save(self, filename=''): i… Read more How Do I Test That I'm Calling Pickle.dump() Correctly?

How Does @mock.patch Know Which Parameter To Use For Each Mock Object?

Looking at this webpage: http://www.toptal.com/python/an-introduction-to-mocking-in-python -- The a… Read more How Does @mock.patch Know Which Parameter To Use For Each Mock Object?

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__

How To Mock Google Cloud Storage Bucket And Link It To Client Object?

I have a function in cloud run and trying to test using mock in Python. How can I mock bucket with … Read more How To Mock Google Cloud Storage Bucket And Link It To Client Object?