Add functions for checking if a spy was called only once.

Review Request #14621 — Created Sept. 19, 2025 and submitted

Information

kgb
master

Reviewers

kgb

A common pattern when using kgb is to check if a spy was called only
once, and sometimes once with specific arguments. Callers had to do this
by checking the call count and then checking the arguments, or to use a
spy operation that would fail if executed more than once.

This introduce two new functions to perform these checks in a simpler
manner:

  • assertSpyCalledOnce()
  • assertSpyCalledOnceWith()

There are also pytest equivalent functions for both.

All unit tests pass on all environments.

Summary ID
Add functions for checking if a spy was called only once.
A common pattern when using kgb is to check if a spy was called only once, and sometimes once with specific arguments. Callers had to do this by checking the call count and then checking the arguments, or to use a spy operation that would fail if executed more than once. This introduce two new functions to perform these checks in a simpler manner: * `assertSpyCalledOnce()` * `assertSpyCalledOnceWith()` There are also pytest equivalent functions for both.
d76767489b23045696d1a5edeec6ffd315b02f6f
Description From Last Updated

Given that we pass this into assertSpyCalledOnce, it can't actually be a call, it can only be a function/spy, right?

daviddavid

Typo: Position -> Positional

daviddavid
david
  1. 
      
  2. kgb/agency.py (Diff revision 1)
     
     
     
    Show all issues

    Given that we pass this into assertSpyCalledOnce, it can't actually be a call, it can only be a function/spy, right?

  3. kgb/agency.py (Diff revision 1)
     
     
    Show all issues

    Typo: Position -> Positional

  4. 
      
chipx86
maubin
  1. Ship It!
  2. 
      
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to master (62ea9f0)