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

Added checks for missing mock usage #44

Merged
merged 1 commit into from
Apr 26, 2024
Merged

Added checks for missing mock usage #44

merged 1 commit into from
Apr 26, 2024

Conversation

nfx
Copy link
Contributor

@nfx nfx commented Apr 26, 2024

R8921: mock-no-assign

some_fn(some_arg, create_autospec(ConcreteType), True)

Mock not assigned to a variable: XXX. Every mocked object should be assigned to a variable to allow for assertions.

To disable this check on a specific line, add # pylint: disable=mock-no-assign at the end of it.

[back to top]

R8922: mock-no-usage

mocked_thing = create_autospec(ConcreteType)
some_fn(some_arg, mocked_thing, True)

Missing usage of mock for XXX. Usually this check means a hidden bug, where object is mocked, but we don't check if it was used correctly. Every mock should have at least one assertion, return value, or side effect specified.

To disable this check on a specific line, add # pylint: disable=mock-no-usage at the end of it.

### `R8921`: `mock-no-assign`

```
some_fn(some_arg, create_autospec(ConcreteType), True)
```

Mock not assigned to a variable: XXX. Every mocked object should be assigned to a variable to allow for assertions.

To disable this check on a specific line, add `# pylint: disable=mock-no-assign` at the end of it.

[[back to top](#pylint-plugin-for-databricks)]

### `R8922`: `mock-no-usage`

```
mocked_thing = create_autospec(ConcreteType)
some_fn(some_arg, mocked_thing, True)
```

Missing usage of mock for XXX. Usually this check means a hidden bug, where object is mocked, but we don't check if it was used correctly. Every mock should have at least one assertion, return value, or side effect specified.

To disable this check on a specific line, add `# pylint: disable=mock-no-usage` at the end of it.
@nfx nfx requested a review from ericvergnaud April 26, 2024 11:51
Copy link

codecov bot commented Apr 26, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@nfx nfx merged commit 9dde7fd into main Apr 26, 2024
8 of 10 checks passed
@nfx nfx deleted the fix/useless-mock branch April 26, 2024 11:59
nfx added a commit that referenced this pull request Apr 26, 2024
* Added checks for missing mock usage ([#44](#44)). This change introduces new checks to a PyLint plugin for use with Databricks, specifically targeting the usage of mock objects in Python code. Two new checks, `R8921` and `R8922`, have been developed to ensure the proper assignment and utilization of mock objects. `R8921` checks for instances where a mock object is not assigned to a variable, suggesting an assignment to enable assertions. `R8922` checks for situations where a mock object is used after creation, recommending an assertion, return value, or side effect for correct usage. To disable these checks on specific lines, users can add comments `# pylint: disable=mock-no-assign` or `# pylint: disable=mock-no-usage`. The commit also includes documentation and examples to guide users in implementing and disabling these checks, enhancing the overall quality and reliability of the code.
@nfx nfx mentioned this pull request Apr 26, 2024
nfx added a commit that referenced this pull request Apr 26, 2024
* Added checks for missing mock usage
([#44](#44)). This
change introduces new checks to a PyLint plugin for use with Databricks,
specifically targeting the usage of mock objects in Python code. Two new
checks, `R8921` and `R8922`, have been developed to ensure the proper
assignment and utilization of mock objects. `R8921` checks for instances
where a mock object is not assigned to a variable, suggesting an
assignment to enable assertions. `R8922` checks for situations where a
mock object is used after creation, recommending an assertion, return
value, or side effect for correct usage. To disable these checks on
specific lines, users can add comments `# pylint:
disable=mock-no-assign` or `# pylint: disable=mock-no-usage`. The commit
also includes documentation and examples to guide users in implementing
and disabling these checks, enhancing the overall quality and
reliability of the code.
nfx added a commit to databrickslabs/ucx that referenced this pull request Apr 26, 2024
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.

1 participant