Course 5897:
Python Pytest for Non-Programmers
(1 day)
Course Description
You do not have to be an expert or even a journeyman in Python to learn how to use pytest to create test frameworks for programs, functions, packages, modules, and APIs. After learning the Python concept and functions needed for writing pytest, you will learn how to use assert to test Python. This is followed by an introduction to parameters and fixtures to reduce typing and create reusable passages of code. Mocking is introduced to show how to test an external interface. A simple method of using classes and directories is explored for the management of tests.
Learning objectives
- How to write a test case
- How to execute a test case
- How to use fixtures for setup and teardown
- How to group test functions
- How to test a user interface with mocking
Who should attend
Individuals with only a minimal knowledge of Python who need to use a testing framework to test programs, functions, packages, modules, and APIs.
Prerequisites
Fundamental knowledge of command line.
Course Outline
Module 1: Basic Python
- Simple Editor for Creating Files
- Simple print
- if and for Statement
- Simple Functions (def and return)
- Context Manager (with)
- assert Statement
- Simple Class Creation
- Introduction to Import
- How to Find Documentation
- Exercise
Module 2: Basic Testing
- Using assert
- Testing for Expected Exceptions
- How to Write a Test Function
- Grouping Tests in Classes
- Using a Subset of Tests
- Documenting Tests
- Exercise
Module 3: Fixtures
- Tests Anatomy
- Introduction to Fixtures
- Using Fixtures for setup and teardown
- Exercise
Module 4: Parameterization
- What Is Parametrization?
- Parameterizing Functions
- Parameterizing Classes
- Exercise
Module 5: Mocking
- What Is Mocking?
- Monkey Patching
- Mocking Classes and Methods
- Creating Errors
- Exercise
Module 6: Projects
- Test Planning
- Features to Test
- Creating Test Cases