![]() |
unittest.mock for an api key - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: unittest.mock for an api key (/thread-38038.html) |
unittest.mock for an api key - silver - Aug-25-2022 I have a method call getKey() returning url and key and I need to test the function using python unittest.mock def getKey(): key = "xxxxx" url = 'www.test.com' return url,key RE: unittest.mock for an api key - ndc85430 - Aug-26-2022 Can you explain further? What do you mean when you say you "need to test the function using unittest.mock"? Is the function really as simple as the code you've shown? Do you really mean you're testing something else and you need to provide a mocked implementation of this function? Can you show the kinds of tests you're trying to write? At this point, it's really not clear what you're trying to do. RE: unittest.mock for an api key - silver - Aug-29-2022 I need to create a def test for that method with a mock data. that's all RE: unittest.mock for an api key - ndc85430 - Aug-29-2022 I didn't write that; you need to fix that post. What does the function do? Is it getting the data from somewhere? Where? If the values are just hardcoded in the test, what value is there in testing it? If you're going to just mock the function, you're not really testing it, either. Of course, the other thing is that you shouldn't put your secret values like API keys in code anyway, as you'll end up storing them in version control and anyone with access to the code will have them (e.g. if the repo is compromised). |