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

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

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.
8e621c79fdc1fc6ed956e4570ed6e630748045c4
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
Checks run (2 succeeded)
flake8 passed.
JSHint passed.
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.