I read this book in order to get an introduction to Pytest, the testing framework associated with the Python programming language, and it proved to be a very thorough introduction indeed. I have a pretty solid background in Python but you don’t need to be an expert programmer to get a lot out of this book. The book does have a small, pre-written Python application called Cards which is used to teach about testing. The Cards app is just a small ticketing system but it helps if you know enough Python to read through and understand how it works. But don’t worry, this book does a great job of introducing a lot of other things besides Pytest.
The book walks you through how to write and run tests against your code. But it also goes way beyond that and talks about testing strategy, testing as it relates to Continuous Integration, and several advanced testing features and methods. It develops your test understanding by starting out with concepts from software testing culture like Arrange-Act-Assert and Given-When-Then and moving on to ideas like the “happy path”, code coverage, line coverage, branch coverage, mocks (also known as test doubles, spies, fakes, or stubs), fixtures, monkey-patching, mock drift, and “Testing Enough to Sleep at Night”. While many concepts are just touched on, it is very helpful to get exposed to all this testing jargon and concepts, especially if you are new to tests or don’t have much experience.
The book itself does not require much typing in of code as it comes with a very well-organized Source Code zip file with almost everything you need. Each chapter has a separate folder and as you work through the book you will find that all the code in the book is there in the Source Code, so all you need to do is type in the commands you’re given to follow along. Each chapter has a few exercises at the end and I found these to be hit or miss as to how well they helped me absorb the material. Some were really good at helping the reader solidify their understanding of the content of the chapter but a few were frustratingly challenging and some were almost not really exercises at all. For example, near the end of the book one exercise was pretty much to read the chapter: “Start at the beginning of the chapter and read and understand the code examples for each technique.” The exercises do not come with solutions either, which I wish was not the case.
But even if the exercises weren't where the author was devoting most of his attention, that’s okay because the rest of the book was really comprehensive, easy to follow along, and packed with a lot of material (but not too much). Besides testing there were also useful tidbits about things like virtual environments in Python, pip, the Python installer, and GitHub Actions. Overall, this is an excellent introduction to the Pytest framework, to testing software, and to testing Python applications. It’s readable, comprehensive, well-organized, and very educational.