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

Mocking A Socket Connection In Python

I am trying to write unit tests for a class in python. The class opens a tcp socket on init. I am t… Read more Mocking A Socket Connection In Python

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

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?

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

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?

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

Mock Builtin 'open" Function When Used In Contextlib

I know this question has been asked before, but I have a particular problem, meaning I want the moc… Read more Mock Builtin 'open" Function When Used In Contextlib

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

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

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

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

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

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 An Entire Module In Python

I have an application that imports a module from PyPI. I want to write unittests for that applicati… Read more Mock An Entire Module In Python