Improve error output when spying on a function goes wrong.

Review Request #9522 — Created Jan. 23, 2018 and submitted


kgb is generally pretty straight-forward to use, but it's possible for
things to go wrong. In the past, failures to unspy could cause confusing
and hard-to-diagnose errors in other tests. Incompatible function
signatures could also result in errors that weren't clear.

This change aims to fix this by making some important checks when spying
on a function. The arguments provided are now checked in order to make
sure they're compatible with the spy, and are in the states required.

If a function is passed in that's already been spied on, an error will
be shown telling the user that the function has been spied on already,
and will show a backtrace of where the spy was set up, helping to debug

The call_fake function's signature is checked for compatibility with
the main function, in an effort to prevent future calls from breaking.
If the functions are incompatible, an error will be shown with the
functions in question, along with their signatures.

This should help a lot with the new signature requirements in kgb 2.0.

Unit tests pass on Python 2.7, 3.4, 3.5, and 3.6.

Tested against our other main codebases to make sure valid signatures
were valid, and invalid ones were caught.

Description From Last Updated

E501 line too long (82 > 79 characters)

Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.


  1. Ship It!
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to master (7096f47)