Chapter 2
Writing Test Functions

In the last chapter, you got pytest up and running. You saw how to run it against files and directories and how many of the options worked. In this chapter, you’ll learn how to write test functions in the context of testing a Python package. If you’re using pytest to test something other than a Python package, most of this chapter still applies.

We’re going to write tests for the Tasks package. Before we do that, I’ll talk about the structure of a distributable Python package and the tests for it, and how to get the tests able to see the package under test. Then I’ll show you how to use assert in tests, how tests handle unexpected exceptions, and testing for expected exceptions.

Eventually, we’ll have a lot of tests. Therefore, you’ll learn how to organize tests into classes, modules, and directories. I’ll then show you how to use markers to mark which tests you want to run and discuss how builtin markers can help you skip tests and mark tests as expecting to fail. Finally, I’ll cover parametrizing tests, which allows tests to get called with different data.

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

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