Skip to content
Advertisement

Tag: python-unittest

Unittesting python?

I have some function with api I have some integration tests: Please could you show how Unittest will look like relatively mine function . Answer Solution Use unittest.mock module. More details can be found here. Explanation patch replaces a real object or function with a mock one. It requires a positional argument target to be filled. This target needs to

How to mock subsequent function calls in python?

I’m new to testing and testing in python. I have a python class that looks like this : File name : my_hive.py I want to mock these functions : pyhive.hive.connect, pyhive.Connection.cursor(used by my class as hive.connect(hive_ip).cursor()) and pyhive.Cursor.execute (used by my class as self.cursor.execute(command) in execute method). I’m able to mock function call hive.connect and also I have been able

Using unittests and moto to mock AWS

I am used to pytest approach for unit testing, without using classes. Today I wanted to give a try to unittest and I wanted to encapsulate my tests inside a TestCase. Then consider this sample test class: Why is not the parameter placed in setUpClass visible from the test? I could imagine that by using the @moto.mock_ssm decorator there it

Python – How can I assert a mock object was not called with specific arguments?

I realize unittest.mock objects now have an assert_not_called method available, but what I’m looking for is an assert_not_called_with. Is there anything like that? I looked on Google and didn’t see anything, and when I tried just using mock_function.assert_not_called_with(…) it raised an AttributeError, meaning the function does not exist with that name. My current solution This works but clutters the code

Advertisement