alchemy-mock
alchemy-mock copied to clipboard
clearing a session's history for testing calls
Hi,
I am using pytest and assert_has_calls
to determine if my session makes certain queries, but I am running into the issue of having multiple tests on the same session. When this happens, the session still has the calls from the previous tests and so tests fail.
what is the best way to get around this? creating a new session every time? wiping the current session's call history?
the other aspect is that i am loading my mocked DB with data via the UnifiedAlchemyMagicMock(data=[ ...])
functionality but i don't want to have to do this for every test as it seems expensive and kind of clunky.
thanks in advance!
perhaps another important piece of this puzzle is that I was imagining essentially creating a single, large UnifiedAlchemyMagicMock()
instance that would hold the data for many tests, but I'm curious if this was the intended use. Or if the vision was that each suite of tests would have their own instance, or something more modular.
dont think there is any specific vision. lib attempts to provide some tooling but how its used is up to the user. as for the session being shared, try using something like reset_mock
which should reset all of the mock state but leave the unified mock data intact
Thank you! That is exactly what I was looking for. Follow up question:
reset_mock
does not seem to clear objects that I've added to a session. is there a way to do this, or do I have to call a delete
?
currently there is no equivalent for reset_mock_data
but that sounds like a good feature to have. PR is welcome or at some point Ill try to add one
Cool. I will keep you updated and, likewise, let me know if you make any progress.
Thanks!