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

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.

主站蜘蛛池模板: 甘洛县| 偃师市| 裕民县| 定兴县| 安泽县| 永平县| 巴东县| 信阳市| 卢氏县| 秦皇岛市| 奉化市| 翼城县| 日喀则市| 阳江市| 花垣县| 东光县| 罗甸县| 离岛区| 台江县| 繁昌县| 镇巴县| 集安市| 河源市| 安国市| 和平县| 庄浪县| 临海市| 普宁市| 定边县| 禄劝| 蕉岭县| 呈贡县| 延寿县| 天门市| 普格县| 彭州市| 平利县| 临夏县| 黔南| 平潭县| 菏泽市|