I'm in that place again where I'm writing tests for my code and I'm like AAH AAH HOW MUCH DO I HAVE TO MOCK? HOW FAR DOWN THE RABBIT HOLE DOES THIS INSANITY GO? :)
#python #nerdlife

To give my vagueposting some specifics in the unlike event someone's interested in helping me firm up my understanding of #python unit testing. I'm trying to test github.com/feoh/omnia_atari/bl which on the one hand seems too trivial a function to bother testing, but I see people do it all the time.

So, do I create mock Search, Results, and Item objects and feedl them to the actual function with mocks applied so it never actually calls the API? Am I insane to think I should even be testing this function?

@feoh I would consider not bothering with a unit test, personally, but if you must, I would just make a mock Item class that has files with names, and pass that in. Use `cast()` to make the type checker happy.

@offby1 See that was my instinct too! But we both know that coverage is a harsh taskmaster and that in certain commercial contexts we're expected to have 90% coverage on our code. My instinct says "There's practically nothing for me to test! I'm just using someone else's API!"

Follow

@feoh rigid coverage requirements are not a good practice, since they drive coverage-oriented tests, not functionality-oriented tests. I would push back on this, if someone imposed it on me, and for a personal project there's no way I'd do it :)

Sign in to participate in the conversation
Wandering Shop

The Wandering Shop is a Mastodon instance initially geared for the science fiction and fantasy community but open to anyone. We want our 'local' timeline to have the feel of a coffee shop at a good convention: tables full of friendly conversation on a wide variety of topics. We welcome everyone who wants to participate, so long as you're willing to abide by our code of conduct.