官术网_书友最值得收藏!

Introducing pytest

Automated testing is considered to be an indispensable tool and methodology for producing high-quality software. Testing should be a part of every professional software developer's toolbox, yet at the same time, it is considered by many to be a boring and repetitive part of the job. But that does not have to be the case when you use pytest as your testing framework.

This book will introduce you to various key features and will teach how to use pytest effectively in your day-to-day coding tasks right from the first chapter, focusing on making you productive as quickly as possible. Writing tests should then become a joy, rather than a boring part of the job.

We will start by taking a look at the reasons why automated testing is important. I will also try to convince you that it is not something that you should have simply because it is the right thing to do. Automated testing is something that you will want to have because it will make your job much easier and more enjoyable. We will take a glimpse at Python's standard unittest module, and introduce pytest and why it carries so much more punch while also being dead simple to get started with. Then, we will cover how to write tests, how to organize them into classes and directories, and how to use pytest's command line effectively. From there, we will take a look at how to use marks to control skipping tests or expecting test failures, how to use custom marks to your advantage, and how to test multiple inputs using the same testing code parameterization to avoid copy/pasting code. This will help us to learn how to manage and reuse testing resources and environments using one of pytest's most loved features: fixtures. After that, we will take a tour of some of the more popular and useful plugins from the vast plugin ecosystem that pytest has to offer. Finally, we will approach the somewhat more advanced topic of how to gradually convert unittest based test suites into the pytest style in order to take advantage of its many benefits in existing code bases.

In this chapter, we will take a quick look at why we should be testing, the built-in unittest module, and an overview of pytest. Here is what will be covered:

  • Why spend time writing tests?
  • A quick look at the unittest module
  • Why pytest?

Let's get started by taking a step back and thinking about why writing tests is considered to be so important.

主站蜘蛛池模板: 德庆县| 柳州市| 林甸县| 垣曲县| 临夏县| 瓮安县| 依安县| 三明市| 临猗县| 甘洛县| 鄂托克前旗| 龙岩市| 小金县| 东丽区| 边坝县| 泸水县| 宽城| 桂平市| 米脂县| 驻马店市| 剑川县| 崇州市| 三河市| 新巴尔虎左旗| 华宁县| 佛学| 阳新县| 林州市| 洛阳市| 吉安市| 龙州县| 广宁县| 资溪县| 黎川县| 东丽区| 班玛县| 镇江市| 汾阳市| 元氏县| 清涧县| 江口县|