You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
pros
cons
The done() method can be called from the test code
This may cause a deviation from expected behavior
assert that done() is called upon destruction
pros
cons
This serves as reminder to update the test code
This seems to have poor behavior with the monkey_patch_sys_paths fixture because it is set to autouse=True (see also move pytest fixture into submodule #9 )
Additional context
Because pytest manages setup and tear-down as an internal implementation detail, this is destructor approach is rather undesirable.
The text was updated successfully, but these errors were encountered:
2bndy5
changed the title
reconsider asserting expectations are used
reconsider asserting how expectations are used
Aug 7, 2024
2bndy5
changed the title
reconsider asserting how expectations are used
reconsider how to assert that expectations are used
Aug 7, 2024
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 move pytest fixture into submodule #9 )Additional context
Because pytest manages setup and tear-down as an internal implementation detail, this is destructor approach is rather undesirable.
The text was updated successfully, but these errors were encountered: