Skip to content

Oct 14: Unit Testing with pytest

Learning Objectives

After today's class, you should be able to:

  • Install and run pytest on your computer.
  • Explain the role of assert in unit tests.
  • Write unit tests for both modules of PA1.

Announcements

  • Mid-Eval survey – LAST CALL!
    • Worth 5 pts like everything else
  • Ch 8 on zyBooks – due Tuesday
  • PA 1 FlexDoko (modules + testing)
    • Readiness Quiz due Tuesday 10/22 (10 pts)
    • Part 1 utilities.py due Friday 10/25 (30 pts)
    • Part 2 game_logic.py due Tuesday 10/29 (60 pts)

Pytest Tutorial

[30 min]

  • Installing/Running pytest
    • If you are absent today, complete this tutorial on your own
    • Bring your completed test_triangles.py to office hours

PA1 Unit Tests

[20 min]

Here is a starting point for testing each module of the project. Example assert statements are provided for each function in each module. You should add at least three more to each test function, so that every requirement of the project is tested.

Note: Docstrings are generally not required for test functions. But you should still have a module docstring with your name and date.