Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clearing a session's history for testing calls #31

Open
roth-mh opened this issue Nov 25, 2019 · 5 comments
Open

clearing a session's history for testing calls #31

roth-mh opened this issue Nov 25, 2019 · 5 comments

Comments

@roth-mh
Copy link

roth-mh commented Nov 25, 2019

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!

@roth-mh
Copy link
Author

roth-mh commented Nov 25, 2019

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.

@miki725
Copy link
Owner

miki725 commented Nov 25, 2019

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

@roth-mh
Copy link
Author

roth-mh commented Nov 25, 2019

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?

@miki725
Copy link
Owner

miki725 commented Nov 26, 2019

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

@roth-mh
Copy link
Author

roth-mh commented Nov 27, 2019

Cool. I will keep you updated and, likewise, let me know if you make any progress.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants