Closed wwzeng1 closed 6 months ago
Thanks for the report. I guess we could just skip this test if pip is not available.
ac0659fdfa
)[!TIP] I can email you next time I complete a pull request if you set up your email here!
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
[X] Modify tests/test_modutils.py
✓ https://github.com/wwzeng1/astroid/commit/b85873bb91286134f11fea76c598117e852ec8df Edit
Modify tests/test_modutils.py with contents:
• First, identify the test or tests that assume the availability of pip or require network access. This could involve tests that directly or indirectly attempt to install packages, check for the presence of pip, or make network requests.
• For tests that require network access, use the pytest marker `@pytest.mark.skipif` to conditionally skip these tests when the environment variable (e.g., `NO_NETWORK`) indicating no network access is set. For example: ```python import os import pytest @pytest.mark.skipif(os.getenv('NO_NETWORK') == '1', reason="Test skipped as it requires network access") def test_some_network_functionality(): # test body ```
• For tests that assume the availability of pip, consider mocking the pip functionality using `unittest.mock` or a similar mocking library if the test logic allows for it. If mocking is not feasible, use the `@pytest.mark.skipif` to conditionally skip these tests based on the presence of pip or a specific environment variable.
• Ensure that any new conditional logic added to skip tests or mock functionality is well-documented in the test code to maintain clarity for future maintainers.
• Run the modified test suite in an environment similar to the user's (i.e., without pip and with no network access) to verify that the issue is resolved and no other tests are adversely affected.
--- +++ @@ -572,7 +572,10 @@ ) -@pytest.mark.skipif(not HAS_URLLIB3_V1, reason="This test requires urllib3 < 2.") +import os +import pytest + +@pytest.mark.skipif(not HAS_URLLIB3_V1 or os.getenv('NO_NETWORK') == '1', reason="This test requires urllib3 < 2 or is skipped due to no network access.") def test_file_info_from_modpath__SixMetaPathImporter() -> None: """Six is not backported anymore in urllib3 v2.0.0+""" assert modutils.file_info_from_modpath(["urllib3.packages.six.moves.http_client"])
tests/test_modutils.py
✓ Edit
Check tests/test_modutils.py with contents:
Ran GitHub Actions for b85873bb91286134f11fea76c598117e852ec8df:
I have finished reviewing the code for completeness. I did not find errors for sweep/test_no_user_warning_assumes_pip_is_avai
.
💡 To recreate the pull request edit the issue title or description. Something wrong? Let us know.
This is an automated message generated by Sweep AI.
I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.
python3 -sBm build -w --no-isolation because I'm calling build with --no-isolation I'm using during all processes only locally installed modules install .whl file in </install/prefix> using installer module run pytest with $PYTHONPATH pointing to sitearch and sitelib inside </install/prefix> build is performed in env which is cut off from access to the public network (pytest is executed with -m "not network")
Checklist
- [X] Modify `tests/test_modutils.py` ✓ https://github.com/wwzeng1/astroid/commit/b85873bb91286134f11fea76c598117e852ec8df [Edit](https://github.com/wwzeng1/astroid/edit/sweep/test_no_user_warning_assumes_pip_is_avai/tests/test_modutils.py) - [X] Running GitHub Actions for `tests/test_modutils.py` ✓ [Edit](https://github.com/wwzeng1/astroid/edit/sweep/test_no_user_warning_assumes_pip_is_avai/tests/test_modutils.py)