Warn when no specs are used
Mock without specs is so forgiving that people often write tests whose asserts do nothing
This is mainly because the apu of mock is severely flawed and error-prone
I agree, but I don't think it's the job of pytest-mock to fix this up.
I plan to write a pylint plugin for this some day, to statically check mocks are always used with spec or autospec.
I wonder, is there a better mocking library (i.e. with a more sane API) which could be exposed to pytest?
There is none, generally mocking is tricky and a sign of bad structure
I wouldn't want to invent one
Hi @RonnyPfannschmidt,
What do you suggest exactly? If one uses mocker.patch without passing autospec=True or a spec, to issue a pytest-warning?
Yes
Fair enough. :smile:
I don't want current users to suddenly start to receive warnings for valid uses of the API though, so I'm thinking of making this an ini option:
[pytest]
mock_warnings = yes # defaults to no
@RonnyPfannschmidt, @The-Compiler, what do you guys think?
:+1:
Thankful I found this issue.
I'm new to mocking and I was wondering why the test wasn't failing when a mock was called more than once.
I had
mocked_function = mocker.patch('app.function')
do_something()
mocked_function.called_once()
The test passed even though called_once isn't even a function.
After I added autospec=True based on the contents of this issue, I am seeing the errors I'm expecting.
+1 for the mock_warnings config option.
Even an update to the docs would be very helpful