Posts tagged "python":

unit testing with pytest—not easily ignored

20 Jul 2019

Days 10–12 of the 100 Days of Code TalkPython course is dedicated to unit testing with pytest, and is a foison of information. Prior to this, I had very little experience with pytest but found it less intuitive than the language itself, and somewhat obscure—at least at first. I think, however, this was because of trying to concinnate the actual tests—much like I would any program—rather than simply hardcoding the input and expected output of a function's given test with the parametrize decorator. Instead, I would essentially try to rewrite the function logic differently to reproduce the desired behaviour. This, however, is counterintuitive because I'm introducing another possibility for faulty logic, albeit in the test, so if the tests pass but both models are flawed, I'd never know. On top of which, I was testing a command-line driven app, so figuring out how to write tests for sys.argv input required additional understanding—and I'm still not entirely sure I've written the most efficient tests but I did achieve complete coverage so I'm satisfied with the result. Nonetheless, what I want to share is the apparent discrepancy between the advertised way to ignore or exclude directories in your project repository, and what's actually needed to get it done.

Tags: code python
Other posts

Generated by emacs org mode

Copyright © 2023 Mark Jamsek