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
Activity
The-Compiler commentedon Sep 29, 2015
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
specorautospec.I wonder, is there a better mocking library (i.e. with a more sane API) which could be exposed to pytest?
RonnyPfannschmidt commentedon Sep 29, 2015
There is none, generally mocking is tricky and a sign of bad structure
I wouldn't want to invent one
nicoddemus commentedon Sep 29, 2015
Hi @RonnyPfannschmidt,
What do you suggest exactly? If one uses
mocker.patchwithout passingautospec=Trueor aspec, to issue apytest-warning?RonnyPfannschmidt commentedon Sep 30, 2015
Yes
nicoddemus commentedon Sep 30, 2015
Fair enough. 😄
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
inioption:@RonnyPfannschmidt, @The-Compiler, what do you guys think?
RonnyPfannschmidt commentedon Sep 30, 2015
👍
chishaku commentedon Dec 21, 2020
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
The test passed even though
called_onceisn't even a function.After I added
autospec=Truebased on the contents of this issue, I am seeing the errors I'm expecting.+1 for the
mock_warningsconfig option.Even an update to the docs would be very helpful