Skip to main content
CodeOath

QA and SDET · Chapter 2

pytest beyond the basics

About this chapter

A test suite starts to hurt in its first months: slow tests, unreadable failures, tests that nobody runs. This chapter takes one shop's suite and adds the parts of pytest that help: custom marks that cannot be misspelt, skip and expected-failure marks, readable test names, fixture scope and layered conftest files, safe checks for floats and error text, capturing printed output and logs, and ways to pick which tests run.

Who it is for: Testers and developers who can write a basic pytest test and want a suite that stays fast, readable and organised as it grows.

You will be able to

  • Register custom marks and turn on strict checking so a typo cannot silently drop a test.
  • Explain the difference between skip, xfail and a strict xfail.
  • Set fixture scope and place shared fixtures in the right conftest file.
  • Compare floating-point results and error messages without brittle checks.
  • Select a part of the suite to run from the command line.

The key idea: A suite is only useful if people run it and understand its failures. Most of what this chapter adds is about that: naming, labelling and selecting tests so the right ones run at the right time and a red result explains itself.

In this chapter

  1. What this chapter adds
  2. Marks that cannot be misspelt
  3. Skip, expected failure and the strict kind
  4. Names that read in a failure
  5. Scope, autouse and layered conftest files
  6. Floats and error text
  7. Output and log lines
  8. Choosing what to run
  9. Mistakes that recur

Locked: needs a plan

You can read chapter 1 free. Chapter 2 is the next one.

What you can do now, free: re-read chapter 1 and try its problems.

What a plan gives you: all chapters of the track you pick and their checks. Professional, one role is ₹329 a month or ₹2,299 a year. It renews until you cancel, and you can cancel any time. Paid plans open at launch.

Why is this locked?

Chapter 1 of every track is free, so you can see how the track reads. The rest of a track and its checks come with a plan, or open as you pass each chapter's check.

The price is for one period, a month or a year. A plan renews until you cancel.

Back to the track