I had a lot of tricky tests to write today that needed mocks against an async SDK.
To get started, I tried out GitHub Copilot "generate tests".
Observations:
=> More informations about this toot | More toots from pamelafox@fosstodon.org
So I eventually modified most tests to "my style" with monkeypatch.setattr whenever possible.
I'm still grateful for Copilot's help since:
=> More informations about this toot | More toots from pamelafox@fosstodon.org
I'm curious what style mocks y'all prefer! should i be magic mocking more??
=> More informations about this toot | More toots from pamelafox@fosstodon.org
@pamelafox
I definitely prefer custom mocks in most cases - magic mocks work when everything is totally unit-ized and so you want to assume nothing about the components surrounding the thing to be tested, but in practice, if you can't actually use the thing in testing, it's good to have at least some imitation of its real behavior, because otherwise you're usually testing nothing
=> More informations about this toot | More toots from jonny@neuromatch.social
@pamelafox
I mean I assume you know more than me, but since you asked!
Also im not saying to not magic mock, it's just for a different situation than the ones I usually run into where I need a mock. More a "when I write tests I usually write the mocks" than a "dont use magicmock"
=> More informations about this toot | More toots from jonny@neuromatch.social
@jonny Okay yeah that makes sense. I think I prefer tests that aren't as clean in terms of "unit-ization" since that gives me additional opportunities to discover issues? Also better type hinting in my tests, since you cant get type hints from Magic mocks. Thanks for sharing your take!
=> More informations about this toot | More toots from pamelafox@fosstodon.org This content has been proxied by September (3851b).Proxy Information
text/gemini