Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inappropriateness in unittest documentation with actual behavior #118912

Closed
AliyevH opened this issue May 10, 2024 · 2 comments · Fixed by #119232
Closed

Inappropriateness in unittest documentation with actual behavior #118912

AliyevH opened this issue May 10, 2024 · 2 comments · Fixed by #119232
Labels
docs Documentation in the Doc dir

Comments

@AliyevH
Copy link
Contributor

AliyevH commented May 10, 2024

Documentation

https://docs.python.org/3/library/unittest.mock.html#auto-speccing

Your tests can pass silently and incorrectly because of the typo.

mock = Mock(name='Thing', return_value=None)
mock(1, 2, 3)
mock.assret_called_once_with(4, 5, 6)  # Intentional typo!

Your tests can pass silently and incorrectly because of the typo.


Expected that tests will pass as written in doc.

But actually script fails with raising error.

raise AttributeError(
AttributeError: 'assret_called_once_with' is not a valid assertion. Use a spec for the mock if 'assret_called_once_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?

Am i missing something? I have tested this in Python3.11 and Python 3.12.
Looks like documentation must be updated or script must work as said in documenation.

Thanks for attention

Linked PRs

@AliyevH AliyevH added the docs Documentation in the Doc dir label May 10, 2024
@blhsing
Copy link
Contributor

blhsing commented May 16, 2024

Note that the doc describes the pre-Python 3.5 behavior. Since Python 3.5, one has to enable the unsafe option to achieve the same behavior:

:exc:`AttributeError`. Passing ``unsafe=True`` will allow access to

unsafe: By default, accessing any attribute whose name starts with assert, assret, asert, aseert or assrt will raise an AttributeError. Passing unsafe=True will allow access to these attributes.

Added in version 3.5.

@shaunagm
Copy link
Sponsor Contributor

I am working on this issue! I hope to finish it today (at the PyCon sprints)

willingc added a commit that referenced this issue May 20, 2024
… guide (#119232)

* Remove description of issue fixed in 3.5 from autospeccing guide

* Make autospeccing note text more succint and lint whitespace

* Add linting changes (missed in last commit)

---------

Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 20, 2024
…eccing guide (pythonGH-119232)

* Remove description of issue fixed in 3.5 from autospeccing guide

* Make autospeccing note text more succint and lint whitespace

* Add linting changes (missed in last commit)

---------

(cherry picked from commit 7e57640)

Co-authored-by: Shauna <shaunagm@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 20, 2024
…eccing guide (pythonGH-119232)

* Remove description of issue fixed in 3.5 from autospeccing guide

* Make autospeccing note text more succint and lint whitespace

* Add linting changes (missed in last commit)

---------

(cherry picked from commit 7e57640)

Co-authored-by: Shauna <shaunagm@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
willingc added a commit that referenced this issue May 20, 2024
…peccing guide (GH-119232) (#119283)

gh-118912: Remove description of issue fixed in 3.5 from autospeccing guide (GH-119232)

* Remove description of issue fixed in 3.5 from autospeccing guide

* Make autospeccing note text more succint and lint whitespace

* Add linting changes (missed in last commit)

---------

(cherry picked from commit 7e57640)

Co-authored-by: Shauna <shaunagm@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
willingc added a commit that referenced this issue May 20, 2024
…peccing guide (GH-119232) (#119284)

gh-118912: Remove description of issue fixed in 3.5 from autospeccing guide (GH-119232)

* Remove description of issue fixed in 3.5 from autospeccing guide

* Make autospeccing note text more succint and lint whitespace

* Add linting changes (missed in last commit)

---------

(cherry picked from commit 7e57640)

Co-authored-by: Shauna <shaunagm@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants