We have a test fixture which patches two classes like below.
@pytest.fixture
def license_fixture(mocker):
mocker.patch('api.license_api.UserLicense')
mocker.patch('api.license_api.UserLicense.userrole', return_value = 'admin') # doesn't work.
l_mock = mocker.patch('api.license_api.LicenseContent')
yield l_mock
LicenseContent serves the api calls for license contents and uses UserLicense.
UserLicense is a third party imported class check for the license user has (using crypto) and serves three puposes.
- All the crypto methods to check for license verification.
- if the user has a valid license via method isvalid()
- to set the correct authorization of user via method userrole()
With patching UserLicense I can test the isvalid, but when I try to patch the method to get user role it does not set the return value of method to the admin and the tests fails.
What is the correct way to patch the method?