Python Pytest for Programmers
Contact us to book this coursePython
On-Site, Virtual
1 day
If you have a working knowledge of Python, you can quickly learn how to use pytest to create test frameworks for programs, functions, packages, modules, and APIs. You will learn how to use assert for testing. This is followed by fixtures to modularize your test code to parameters and fixtures to reduce typing and to create re-useable passages of code. Mocking is introduced to show how to test an interface. A simple method of using classes and directories is explored for management of tests. Lastly, the course explores a method of deciding what needs to be tested and what your test coverage is.
Learning objectives
- Learn to write Python pytest
- 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
Who should attend
Individuals with working 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
- Introducing Pytest
- Using assert
- Testing for Expected Exceptions
- How to Write a Test Function
- Grouping Tests in Classes
- Using a Subset of Tests
- Exercise
- What Is a Fixture?
- Creating Fixtures for Setup and Teardown
- Fixture Scope
- Management of Fixtures
- Exercise
- What Is Parametrization?
- Parameterizing Functions
- Parameterizing Classes
- Exercise
- What Is Mocking?
- Monkeypatching
- Creating Mocking Classes and Methods
- Creating a Mocking Attribute
- Management of Mocking
- Exercise
- Software Project Layout and Tests
- Test Scoping
- Features to Test
- Creating Test Cases
- How to Calculate Test Coverage
- Setting Up Configuration Files