Mocking "platform.release()" in python testing?

  python, testing, unit-testing

I am writing unit tests for my python code, and the below code under the "-aws" at the bottom isn’t getting covered. How can I set mocks so that "platform.release()" will contain "-aws" in the name?

I was looking at mock.patch.dict(os.platform, {"release": "-aws"}) but that wasn’t working, with it saying AttributeError: type object 'Mock' has no attribute 'patch'

import os, platform

def sendMsg(msg):
  release_name = platform.release()
  if "-aws" in release_name:
    ...

Source: Python Questions

LEAVE A COMMENT