Open 2bndy5 opened 1 month ago
I'm inclined to go with option 1 because tests could expectedly fail (pytest.marks.xfail
). Relying on a mock's destructor would force users' test code to overcompensate for a mock's behavior that asserts all expectations are used. It would be better to let a mock's done()
be optionally invoked when appropriate.
As this library is largely influenced by embedded-hal-mock (for rust), going with option 1 is a serious deviation from that lib's design.
Currently, the expectations are checked that they are all used upon destruction of the mocked object. However, pytest will ignore any exception thrown by a destructor. This leaves a traceback in the pytest output about "Ignored exception" when some exceptions were not used.
Possible solutions
let unused expectations go unchecked
done()
method can be called from the test codeassert that
done()
is called upon destructionmonkey_patch_sys_paths
fixture because it is set toautouse=True
(see also #9 )Additional context
Because pytest manages setup and tear-down as an internal implementation detail, this is destructor approach is rather undesirable.