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

Fail pytest runs on warnings #7809

Merged
merged 10 commits into from
Nov 23, 2022

Conversation

jacobtylerwalls
Copy link
Member

@jacobtylerwalls jacobtylerwalls commented Nov 20, 2022

Type of Changes

Type
βœ“ πŸ”¨ Refactoring

Description

I've opened a few PRs over time to clean up warnings in the test suite when I see them. Figured we might as well fail CI so that we don't merge with known issues.

Failure expected due to #7795, mentioned here: #7795 (comment). Edit: resolved.

@jacobtylerwalls jacobtylerwalls added Maintenance Discussion or action around maintaining pylint or the dev workflow Skip news πŸ”‡ This change does not require a changelog entry labels Nov 20, 2022
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
clavedeluna
clavedeluna previously approved these changes Nov 21, 2022
Copy link
Collaborator

@clavedeluna clavedeluna left a comment

Choose a reason for hiding this comment

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

Really good catch here and sorry one of my PRs introduced a warning. Looks like now it's failing the test run with it! Let me know if you want to fix the warnings in this PR or you want me to intervene via another issue/ PR.

@DudeNr33
Copy link
Collaborator

I have to look at this more closely this evening. Currently I don't see why this change should work as intended.

@@ -89,6 +89,7 @@ test = "pytest"
testpaths = ["tests"]
python_files = ["*test_*.py"]
addopts = "--strict-markers"
filterwarnings = "error"
Copy link
Collaborator

Choose a reason for hiding this comment

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

will this make pytest fail at any len(warnings) > 0?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep!

@jacobtylerwalls
Copy link
Member Author

Currently I don't see why this change should work as intended.

There's one pyreverse test that still makes use of __implements__, so it raises a DeprecationWarning when it's loaded. Or were you asking about something else?

@jacobtylerwalls
Copy link
Member Author

Let me know if you want to fix the warnings in this PR or you want me to intervene via another issue/ PR.

If you have time to help, that would be great. You can either push to my branch (GH's own editor makes that easier than it used to) or open a new PR, whatever works πŸ‘πŸ»

Copy link
Collaborator

@DudeNr33 DudeNr33 left a comment

Choose a reason for hiding this comment

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

Managed to squeeze the review in. As suspected the change does not help in this case, but I can understand the confusion (the Generator return type together with TESTS sounding like plural it seems like we are iterating over different directories here).

Let me know if you need more help!

@@ -30,7 +30,14 @@ def project(get_project: GetProjectCallable) -> Generator[Project, None, None]:
with _test_cwd(TESTS):
project = get_project("data", "data")
linker = inspector.Linker(project)
linker.visit(project)
if "clientmodule_test" in str(project):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is never true, as the project is always the same here (the data directory underneath /tests). The string representation of project does not contain the substring clientmodule_test.

I would suggest just get rid of the if condition here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried that, but I received many failures. I'll try again tonight. πŸ€”

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, but with the current change we are always hitting the else, and nothing has changed effectively compared to before.
I haven't looked at how to actually properly catch the warning, my guess would be that there are some other tests that don't catch this Warning yet (the majority of the legacy tests for pyreverse work with the same test data). I will also take a closer look at it this or tomorrow evening!

Copy link
Collaborator

@DudeNr33 DudeNr33 Nov 22, 2022

Choose a reason for hiding this comment

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

Neither on your branch nor on main could I reproduce the deprecation warnings on the pyreverse tests.
On a recent CI run there is only one DeprecationWarning for some other test case, but not for pyreverse.
Am I missing something here like an option I have to turn on first?

Edit: That's strange - If I only run pytest tests/pyreverse/test_inspector I can see the DeprecationWarning in the warnings summary, but if I run pytest tests/pyreverse/ instead it does not appear. Maybe a bug in pytest?

Edit 2: I have the feeling that if a specific DeprecationWarning is caught and suppressed anywhere in the test suite using pytest.warns(DeprecationWarning), it will be suppressed for the whole remaining test suite as well.
While reading the docs I also found that it is possible to filter and ignore warnings for an entire test module via pytestmark = pytest.mark.filterwarnings("ignore:pyreverse:DeprecationWarning") at the top of the file, which is more convenient than wrapping all .visit() calls into with pytest.warns() blocks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry @DudeNr33 you're quite right, the else branch always executes. I've just pushed a change to just ignore warnings in this fixture.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 3528574134

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 30 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.003%) to 95.425%

Files with Coverage Reduction New Missed Lines %
pylint/checkers/variables.py 30 97.3%
Totals Coverage Status
Change from base Build 3527524786: -0.003%
Covered Lines: 17520
Relevant Lines: 18360

πŸ’› - Coveralls

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Seems like no contributers used python 3.7 anymore :D

Copy link
Collaborator

@DudeNr33 DudeNr33 left a comment

Choose a reason for hiding this comment

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

As mentioned in the discussion I think there is a bug in pytest when it comes to suppress warnings, and if that's true and the bug gets resolved we may have to update more of the pyreverse test files - but until then all fine from my side! 😊

@Pierre-Sassoulas Pierre-Sassoulas merged commit 694d302 into pylint-dev:main Nov 23, 2022
@jacobtylerwalls jacobtylerwalls deleted the fail-on-warnings branch November 23, 2022 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Discussion or action around maintaining pylint or the dev workflow Skip news πŸ”‡ This change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants