Skip to main content

3 posts tagged with "python"

View All Tags

· 4 min read
Hreniuc Cristian-Alexandru

An example on how you can mock things in python.

Let's assume we have the following folder structure:

 - project
- src
- test
- utils
- aws.SSMClient.AWSFactory
- and so on, check below in the code

To run the unit tests:

cd src

python3 -m unittest discover -p "*test*" -v

If you added a new subfolder in test, you need to also add an empty file called, to be discovered by the command from above.

When adding unit tests, you can enable logging for a specific testa case if you add the following line in the beginning of the test case:


Also, in all unit tests we inject fake response from aws using mock and we also enforce that a method be called with a specific set of params. To see the mock calls made on the boto3(aws) instances you can temporary add the following prints:


This will print all calls made on the aws instances, this way you can verify and add mock expectations in your tests.

In the file below you will notice that we import fake data or Helpers, those things are just strings that we want to return or the call params of a mock method, eg:

· One min read
Hreniuc Cristian-Alexandru


find ~ -name


Add there the following contents:

def qdump__ClassType1(d, value):
m_member1 = value["m_member1"].integer()
m_member2 = value["m_member2"].integer()
miliseconds = int(m_member1 * 1000 / m_member2)
d.putValue(str(miliseconds) + str("ms (")+ str(m_member1) + str("m1, ") + str(m_member2) + str("m2)"))

def qdump__ClassType2(d, value):
position = value["m_position"]
qdump__FramesDuration(d, position)

The ClassType2 will be displayed like this: 3642331ms (160626834m1, 44100m2).

For more examples, check: /home/cristi/Qt/Tools/QtCreator/share/qtcreator/debugger/