-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 two incorrect/broken tests in tests/checkers/unittest_imports.py
#9911
Conversation
Not sure if changlog should be updated in this situation. Let me know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the pull request ! sys.path is tricky to test and can cause massive problem (with namespace packages in particular), so let's be cautious before modifying it.
@@ -92,28 +93,33 @@ def test_relative_beyond_top_level_four(capsys: CaptureFixture[str]) -> None: | |||
assert errors == "" | |||
|
|||
def test_wildcard_import_init(self) -> None: | |||
module = astroid.MANAGER.ast_from_module_name("init_wildcard", REGR_DATA) | |||
import_from = module.body[0] | |||
context_file = os.path.join(REGR_DATA, "dummy_wildcard.py") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the context file necessary and doesn't it change what we're testing ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context file would be used to specify that the file where the import statement for the module. I was trying to understand the intent of the code and the test and trying to guess what we are trying to achieve. The existing test only works if the search directory is in the sys.path
. If we want this test to succeed without changing sys.path
, then I think we need to change (fix?) the find_spec
in astroid.interpreter._import.spec
module. It is not considering the directory we are passing to it. Shall I attempt to push a fix and see if it works?
I also looked at the tests in test_manager.py in the astroid repo. There is no test for ast_from_module
when the second argument is specified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes make sense to me actually.
@Pierre-Sassoulas What do you think?
If you see the search code here, even though |
I also think it make sense but I don't understand a lot :D feel free to push the fix you envision @akamat10 , it'll help us (me) understand better imo |
Ok I tried to get _find_spec_with_path to respect the |
I took a look at the tests within astroid repo. I see quite a few modify |
@akamat10 Could you rebase this so the @Pierre-Sassoulas Shall we merge this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @akamat10 !
Type of Changes
Description
This PR addresses an issue with two tests (
test_wildcard_import_init
andtest_wildcard_import_non_init
) in tests/checkers/unittest_imports.py that I discovered while attempting to fix #9883.The issue with the tests is that the tests are invalid and only work due to modified
sys.path
in https://github.com/pylint-dev/pylint/blob/main/tests/pyreverse/conftest.py#L70. This can be reproduced by running the test on only the file:the above command fails and I see the following:
The fix is to augment the
sys.path
as part of the test.Refs #9883