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

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

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

Return Value Not Set As Intended When Mocking A Method With @mock.patch.object

My test should with reason succeed as I'm giving a return value with mocker.return_value, which… Read more Return Value Not Set As Intended When Mocking A Method With @mock.patch.object

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?

How Do We Ensure That The Calls In The Mock.call_args_list Contain Calls With Arguments At The Same State Of When The Mock Object Was Called?

from mock import Mock j = [] u = Mock() u(j) # At this point u.call_args_list == [call([])] print u… Read more How Do We Ensure That The Calls In The Mock.call_args_list Contain Calls With Arguments At The Same State Of When The Mock Object Was Called?

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

Python Mock And Libraries That Are Not Installed

I am working on software for a robot, which is normally run on the Raspberry Pi. Let's consider… Read more Python Mock And Libraries That Are Not Installed

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`

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

How To Mock Just The Method Inside The Class

Trying to write a testcase for my class based function. This is skeleton of my class class Library(… Read more How To Mock Just The Method Inside The Class

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

Concept: Mocking DB Python

I'm working with postgresql and I have used MagicMock to test, but I'm not sure that I have… Read more Concept: Mocking DB Python

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

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