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 test imports #9982

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

nickdrozd
Copy link
Collaborator

Type of Changes

Type
βœ“ πŸ”¨ Refactoring

Description

Trying to run pytest locally without git package installed raises ModuleNotFoundError, even though primer is not run locally. Similar for pytest_benchmark.

This MR delays imports from git until they are actually used. The pytest_benchmark import was only used for typechecking, so it is pushed under TYPE_CHECKING flag. (This is yet another benefit to separating typechecking imports from runtime imports.)

@nickdrozd nickdrozd added the Skip news πŸ”‡ This change does not require a changelog entry label Sep 28, 2024
Copy link

codecov bot commented Sep 28, 2024

Codecov Report

All modified and coverable lines are covered by tests βœ…

Project coverage is 95.80%. Comparing base (c0ecd70) to head (d53332c).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9982   +/-   ##
=======================================
  Coverage   95.80%   95.80%           
=======================================
  Files         174      174           
  Lines       18934    18934           
=======================================
  Hits        18140    18140           
  Misses        794      794           
Files with missing lines Coverage Ξ”
pylint/testutils/pyreverse.py 98.11% <100.00%> (+0.03%) ⬆️
pylint/typing.py 100.00% <ΓΈ> (ΓΈ)

This comment has been minimized.

@nickdrozd
Copy link
Collaborator Author

Seems to work okay, but I guess the primer files aren't covered? Is there a way to skip the coverage check for this one?

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.

I don't think there's anything to fix, this is due to pylint not being installed properly:

testutils = ["gitpython>3"]

A possible solution would be to move the test utils in another package entirely, the name is reserved https://pypi.org/project/pylint-testutils/.

@nickdrozd
Copy link
Collaborator Author

Okay, I installed the testutils and the Git imports works fine. The Pytest benchmark still isn't installed though, so running pytest crashes immediately with an import error. I don't know if that's something that needs to be fixed, but the typechecking import can be moved either way.

I dropped the Git import commit and replaced it with an unrelated change that moves GetProjectCallable type to testutils.

@nickdrozd nickdrozd mentioned this pull request Sep 29, 2024
@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Sep 29, 2024

The typing being all guarded is not consensual among pylint core maintainers (there's an ongoing discussion between you and Marc about this), let's not change anything before it is resolved.

Also I'm not sure what the issue is, there's a test requirements file that you need to pip install -r if you want to launch the tests locally ?

pytest-benchmark~=4.0

https://pylint.readthedocs.io/en/stable/development_guide/contributor_guide/tests/install.html#basic-installation

Copy link
Contributor

πŸ€– According to the primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

This comment was generated for commit d53332c

@nickdrozd
Copy link
Collaborator Author

My understanding is that the concern is with using the type guard project-wide. Is there an objection to using the type guard in each and every case? For this particular import, using the guard provides a clear material benefit: it allows running tests without all the test dependencies installed.

@Pierre-Sassoulas
Copy link
Member

There's a clear benefit to installing the test requirements from the test requirements file: you're not going to run into strange issue because you have an out of date dependency and we won't have to complexify the code to accomodate partially installed tests requirements.

Also introducing unneeded typing guards MR by MR is not very different from introducing them all at once. The discussion still need to happens. I found the 'this is going to create churn' argument convincing and imo the 'default' at the moment is to not have typing guard unless necessary so if Marc thinks strongly that it's not desirable I would be in favor of not changing anything unless we have strong arguments in favor (like major performance improvment, or it becoming the standard).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip news πŸ”‡ This change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants