Testing

Case Study: Building Software in Python

Mark Pedigo

Principal Data Scientist

Roadmap

Roadmap showcasing what parts of the project we've finished and which we'll be starting.

Case Study: Building Software in Python

Why automated testing?

  • Automatic, software-driven testing
  • No human intervention required
  • Simple checks to comprehensive assessments

A robot testing code

Case Study: Building Software in Python

Benefits of automated testing

  • Improved code quality
  • Risk mitigation
  • Enhanced user experience
Case Study: Building Software in Python

What Do Unit Tests Do?

  • Individual components or functions tested individually
  • Focus on the smallest parts of an application
  • Verify expected output given input

A magnifying glass examining blocks

Case Study: Building Software in Python

What is the pytest library?

  • Popular testing framework for Python
  • Supports unit testing
  • Known for simplicity, flexibility, and features
Case Study: Building Software in Python

Advantages of pytest

  • Simplicity and readability
  • Powerful fixtures
  • Integrates with other tools
Case Study: Building Software in Python

Unit test - example

# math.py
def add(a, b):
  return a + b
# test_math.py
import pytest
def test_add():
    assert add(2, 3) == 5
    assert add(-1, 1) == 0
    assert add(0, 0) == 0
    assert add(-5, -7) == -12

Run in the console:

pytest test_math.py

===== test session starts ===== collected 1 item test_math_functions.py . [100%] ====== 1 passed in 0.03s ======
Case Study: Building Software in Python

Let's practice!

Case Study: Building Software in Python

Preparing Video For Download...