Testing the code so far

How would we know whether the code is good, anyway? The only good way is to rigorously test your code. While it may sound like a lot of somewhat unnecessary work, it is a practice that will repay you many times over in the future—once you're sure your code behaves as intended, it is much easier to add new features and be sure that they didn't break any of the existing ones. Furthermore, you can upgrade dependencies or compare different implementations, all being sure that your code behaves as intended.

As for many other things, Python has a standard library for testing—unittest. In contrast to most of the standard libraries, however, unittest is fairly unpopular. Instead, another library, pytest, is considered the de facto industry standard for Python testing, as it provides a clean and reusable pattern of code and has support for plugins—indeed, there are a lot of plugins available to support. 

When poetry generated a scaffolding for our package, it generated a tests folder. That is where our tests will live; this way, they live separately from the package and won't be installed with it. Now let's dive in and write our first test.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.7.116