Skip to content

Add SpyType for mocker.spy results#582

Merged
nicoddemus merged 5 commits into
pytest-dev:mainfrom
Himanshuagrawal4:PRO/pytest-mock-spy-type-attributes
Jun 5, 2026
Merged

Add SpyType for mocker.spy results#582
nicoddemus merged 5 commits into
pytest-dev:mainfrom
Himanshuagrawal4:PRO/pytest-mock-spy-type-attributes

Conversation

@Himanshuagrawal4
Copy link
Copy Markdown
Contributor

Summary

  • add a public SpyType for mocker.spy() return values
  • expose the spy-only attributes (spy_return, spy_return_iter, spy_return_list, spy_exception) to type checkers
  • export SpyType from pytest_mock and add a regression test

Closes #547.

Validation

  • pre-commit run --files CHANGELOG.rst src/pytest_mock/__init__.py src/pytest_mock/plugin.py tests/test_pytest_mock.py
  • python -m mypy src tests
  • python -m pytest tests/test_pytest_mock.py::test_spy_type tests/test_pytest_mock.py::test_instance_method_spy tests/test_pytest_mock.py::test_spy_return_iter_resets -q
  • python -m pytest tests -q -k "not introspection"
  • python -m compileall -q src\pytest_mock
  • git diff --check

Notes

The full local python -m pytest tests -q run has four existing assertion-introspection output failures on this Windows/Python 3.13 environment. They appear unrelated to this typing change, so this PR leaves those tests untouched.

@Himanshuagrawal4 Himanshuagrawal4 marked this pull request as ready for review June 3, 2026 07:05
Comment thread tests/test_pytest_mock.py Outdated
Comment thread tests/test_pytest_mock.py Outdated
@Himanshuagrawal4 Himanshuagrawal4 marked this pull request as draft June 4, 2026 19:23
@Himanshuagrawal4 Himanshuagrawal4 marked this pull request as ready for review June 4, 2026 19:35
Comment thread src/pytest_mock/plugin.py
nicoddemus and others added 2 commits June 5, 2026 10:04
Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
@nicoddemus nicoddemus merged commit 4f59636 into pytest-dev:main Jun 5, 2026
18 checks passed
@nicoddemus
Copy link
Copy Markdown
Member

Thanks @Himanshuagrawal4!

@glukki
Copy link
Copy Markdown

glukki commented Jun 5, 2026

OMG, you made it! Thank you @Himanshuagrawal4 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spy type is missing extra attributes

3 participants