| Yes. The test passes. https://imgur.com/a/4qlTKlc To try to monkey patch this in, you would need to also assert that it wasn't called with [2, 4, 6, 8, 10]. At which point, I would again ask "why are you testing that it _wasn't_ called with a given set of values?" The comment at the root of this is "Unit tests catch that kind of stuff". ... But unit tests aren't for testing internals of implementation but rather observable aspects of a function. Consider if the code was written so that it was def print_evens(nums):
for n in nums:
if n % 2 == 0:
print(n)
instead (with the filter being used in func())This isn't something that unit tests can (or should) identify. It would come out in a code review that there is redundant functionality in func and print_evens. Using ChatGPT or another tool to assist in doing code reviews can be helpful (my original premise). https://chatgpt.com/share/697a64a6-33c0-8011-a0f8-ca4fec74ab... ChatGPT properly identifies the duplicated functionality (even though the code is using different idioms for doing the filtering for even numbers). |
Which I guess, idk maybe think through the testing more and your code more before jumping to conclusions about how things are?
Testing is one tool you have, and it can test the internal like this. Obviously there's a use for it if its in the Python stdlib
This is in mockito
https://stackoverflow.com/questions/39452438/mockito-how-to-...
this is in google testing library for cpp
https://google.github.io/googletest/gmock_for_dummies.html
> Specify your expectations on them (How many times will a method be called? With what arguments? What should it do? etc.).
If you never heard of this, I guess you learned something new? Im not a tutor though. I would read the docs more and experiment. Maybe chatgpt can help you with how tests can be written.