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

Fix too broad suppression of unused-argument warnings #251

Merged
merged 3 commits into from Nov 4, 2019

Conversation

psrb
Copy link
Contributor

@psrb psrb commented Oct 27, 2019

This PR introduces the following changes:

Pass arguments provided to scripts/test.sh along to test_func/pytest

Previously you had to modify scripts/test.sh to pass new arguments to pytest. Now you can call scripts/test.sh --capture=no if you want to drop into the debugger when running tests 😃

Ensure that load_configuration of pylint-django is called when running tests

Changes made in load_configuration can now be tested.

The main part of this PR is the bugfix for #249

As described in #249 the suppression of the unused-argument warning if a function contains an argument named request was too broad.

Implementation
  • I have reverted most of the changes made in e4c8fc7 and
  • pylint-django now extends Pylints ignored-argument-names regex to included request. This way other unused-argument warnings will still be issued!
  • I have added two test cases verify this behaviour
    • I documented how to define the expected confidence level in the txt files. The confidence level for UserView.get was INTERFERENCE and not the default value of HIGH.

Note on failing tests

I have tested my changes locally using Pylint 2.3.1. The CI pipeline currently fails because of changes made in the Pylint repository (see #250 for more information).

@psrb psrb changed the title Bugfix request unused arguments Fix too broad suppression of unused-argument warnings Oct 27, 2019
@coveralls
Copy link

Pull Request Test Coverage Report for Build 838

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at ?%

Totals Coverage Status
Change from base Build 781: 0.0%
Covered Lines:
Relevant Lines: 0

💛 - Coveralls

@coveralls
Copy link

coveralls commented Oct 27, 2019

Pull Request Test Coverage Report for Build 860

  • 13 of 13 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.0%) to 88.567%

Totals Coverage Status
Change from base Build 854: 1.0%
Covered Lines: 5787
Relevant Lines: 6534

💛 - Coveralls

README.rst Outdated Show resolved Hide resolved
pylint_django/augmentations/__init__.py Show resolved Hide resolved
README.rst Show resolved Hide resolved
@atodorov
Copy link
Contributor

Can you rebase on top of #252 so we can see that tests work while we wait for it to get reviewed/merged ?

@psrb psrb force-pushed the bugfix-request-unused-arguments branch 2 times, most recently from 1cf723f to c817213 Compare October 30, 2019 18:41
README.rst Outdated
@@ -124,6 +124,9 @@ a test name, and insert into it some code. The tests will run pylint
against these modules. If the idea is that no messages now occur, then
that is fine, just check to see if it works by running ``scripts/test.sh``.

You can pass any pytest command line argument to ``scripts/test.sh``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's python, not pytest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the wording may be confusing or I understand something wrong, but I still think that it should be pytest, not python:

$ ./scripts/test.sh --version
This is pytest version 5.2.2, imported from ...

My suggestion to hopefully make it a clearer:

Any command line argument passed to scripts/test.sh will be passed to the internal invocation of pytest. For example if you want to debug the tests you can execute scripts/test.sh --capture=no. A specific test case can be run by filtering based on the file name of the test case ./scripts/test.sh -k 'func_unused_arguments'.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh, I must be blind. I was looking at what test.sh executes and totally missed the part that we call pytest.main() in test_func.py.

+1 for the last suggestion, it does make things very clear & sorry for the noise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. No worries

pylint_django/augmentations/__init__.py Show resolved Hide resolved
@psrb psrb force-pushed the bugfix-request-unused-arguments branch from b273a43 to d564872 Compare November 2, 2019 13:38
Previously you had to modify scripts/test.sh to add command line
arguments to pytest. Now you can add them directly when calling test.sh.

This is useful if you, for example, want to filter the executed tests
using `-k`.
When running the tests the plugin was loaded but its
`load_configuration` function was not called. The function needs to be
called so changes to config entries can be tested.
…v#249)

The previous implementation (result of pylint-dev#155) of disabling the
unused-argument warning for functions/methods having an argument named
`request` was to broad. As soon as a function/method contains a
`request` argument no unused-argument warning will be issued for this
function anymore, even though some other arguments are unused!

This commit monkey patches `VariablesChecker._is_ignored_named` to
specifically suppress the generation of unused-argument warnings for
arguments named `request`.
This way unused-argument warnings will still be issued for every other
unused argument of the function/method.
@psrb psrb force-pushed the bugfix-request-unused-arguments branch from d564872 to a7cb1e1 Compare November 3, 2019 19:11
@psrb
Copy link
Contributor Author

psrb commented Nov 3, 2019

I am done now. I have rebased the branch onto the current master and tidied the commit history. After a final review this can be merged.

@atodorov atodorov merged commit 5f752b6 into pylint-dev:master Nov 4, 2019
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.

None yet

3 participants