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

[Task]: Add flake8 lint rule against using assert_ mock methods #15333

Open
1 task
diox opened this issue Feb 4, 2025 · 0 comments
Open
1 task

[Task]: Add flake8 lint rule against using assert_ mock methods #15333

diox opened this issue Feb 4, 2025 · 0 comments
Labels
needs:info repository:addons-server Issue relating to addons-server

Comments

@diox
Copy link
Member

diox commented Feb 4, 2025

Description

Python's mock without autospec will happily execute unknown methods without a warning, so it's generally best to avoid mock's special methods that return something truthy or perform the assertion directly like assert_called_with() - accidentally calling <mock>.asssert_called_with (typo asssert) would happily return without raising anything.

Checking call_args_list or call_count is more verbose/uglier but safer.

See https://engineeringblog.yelp.com/2015/02/assert_called_once-threat-or-menace.html on that topic (nowadays assert_called_once() does exist, but that wasn't the case back then)

We should have a flake8 plugin linting our code against that.

Acceptance Criteria

Milestones/checkpoints

Preview Give feedback

Checks

  • If I have identified that the work is specific to a repository, I have removed "repository:addons-server" or "repository:addons-frontend"

┆Issue is synchronized with this Jira Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs:info repository:addons-server Issue relating to addons-server
Projects
None yet
Development

No branches or pull requests

1 participant