Skip to content

Improve StrictMock guidance for undefined callables - #380

Open
KSAGlory wants to merge 1 commit into
facebook:mainfrom
KSAGlory:fix/strictmock-callable-suggestions
Open

KSAGlory wants to merge 1 commit into
facebook:mainfrom
KSAGlory:fix/strictmock-callable-suggestions

Conversation

@KSAGlory

Copy link
Copy Markdown

What:

Improves UndefinedAttribute messages for callable attributes on templated StrictMock objects. Synchronous callables now point to testslide.mock_callable(), while coroutine functions point to testslide.mock_async_callable().

Fixes #128

Why:

The existing message only says that the attribute must be set. For template methods, that misses TestSlide's dedicated callable-mocking APIs, which provide call validation and expectations.

How:

StrictMock.__getattr__ inspects the matching template attribute and appends a targeted tip. The tests cover synchronous and asynchronous instance, static, and class methods while preserving the existing message for non-callable attributes.

Risks:

Low. The exception type and existing message prefix are unchanged. Only callable attributes receive one additional guidance line.

Test results:

  • Passed all six focused synchronous and asynchronous callable guidance cases.
  • Passed the existing non-callable undefined-attribute cases.
  • Passed the full StrictMock test file except the pre-existing Python 3.13-incompatible subclass context.
  • Ruff formatting passes.
  • Ruff reports no warnings beyond those already present on main.
  • git diff --check passes.

Testing limitation:

The complete StrictMock test file cannot pass locally on Python 3.13 because the existing subclass setup rejects Python 3.13's __firstlineno__ attribute as unsupported. This failure occurs on untouched main and is unrelated to this change. The repository CI uses Python 3.10.

Checklist:

  • Added tests, if you've added code that should be tested
  • Updated the documentation, if you've changed APIs - N/A, no API change
  • Ensured the test suite passes - Focused and compatible tests pass; full local execution is blocked by the pre-existing Python 3.13 issue described above
  • Made sure your code lints - No new lint warnings
  • Completed the Contributor License Agreement ("CLA")

@meta-cla meta-cla Bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggest mock_(async)_callable from StrictMock

1 participant