Skip to content

Conversation

@sambhavnoobcoder
Copy link
Contributor

@sambhavnoobcoder sambhavnoobcoder commented Feb 22, 2025

Problem

The test_clear_import_cache() test in tests/utils/test_import_utils.py is affecting the state of subsequent tests, causing failures in the test suite. This is happening because the test modifies the global module cache without properly restoring it.

Solution

Updated the test to:

  1. Save the initial state of all transformers modules before running the test
  2. Run the test to verify clear_import_cache() functionality
  3. Restore the initial state after the test completes, including proper handling of _LazyModule instances

The core functionality of clear_import_cache() remains unchanged - this fix only addresses test isolation.

Edit : #36334

Screenshots

Screenshot 2025-02-22 at 4 43 58 PM

cc @dvrogozh

Copy link
Contributor

@dvrogozh dvrogozh left a comment

Choose a reason for hiding this comment

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

This PR does not work to address the reported issue #36334. Consequent tests fail as before.

$ git log -1 --oneline
c20c8466c4 (HEAD -> pr_36345) style fixes

$ python3 -m pytest tests/utils/test_import_utils.py tests/utils/test_logging.py
...
tests/utils/test_import_utils.py::test_clear_import_cache PASSED                                                                                                                                       [ 14%]
tests/utils/test_logging.py::HfArgumentParserTest::test_advisory_warnings PASSED                                                                                                                       [ 28%]
tests/utils/test_logging.py::HfArgumentParserTest::test_env_invalid_override FAILED                                                                                                                    [ 42%]
tests/utils/test_logging.py::HfArgumentParserTest::test_env_override FAILED                                                                                                                            [ 57%]
tests/utils/test_logging.py::HfArgumentParserTest::test_integration PASSED                                                                                                                             [ 71%]
tests/utils/test_logging.py::HfArgumentParserTest::test_set_level PASSED                                                                                                                               [ 85%]
tests/utils/test_logging.py::test_set_progress_bar_enabled PASSED                                                                                                                                      [100%]
...

@sambhavnoobcoder : I see you attached the screenshot with a single test passing - ``test_clear_import_cache`. But question is not whether this test pass or not if ran alone, but whether group of tests ran on the same command line pass. The #36334 has such a line to reproduce the issue.

@Rocketknight1
Copy link
Member

cc @ydshieh to this PR and the related issue at #36334

@sambhavnoobcoder
Copy link
Contributor Author

Apologies for the delay! This was a minor test isolation issue related to the environment—completely slipped my mind. I've fixed it now, and all test cases, including the previously failing ones, are passing. Hopefully, this gets merged soon so we can wrap up this issue quickly.

Screenshot 2025-03-14 at 6 51 31 PM

Copy link
Collaborator

@ydshieh ydshieh left a comment

Choose a reason for hiding this comment

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

Thank you @sambhavnoobcoder for this PR. I think it could be fixed in a very simple way by using some existing functions within the library. Could you try what I mentioned in the comments 🙏 ?

@sambhavnoobcoder
Copy link
Contributor Author

thank you for the comments @ydshieh . i have looked at all of them and resolved all of them . please tell me if you need anything else here . i'll make that happen as well .

@ydshieh
Copy link
Collaborator

ydshieh commented Mar 14, 2025

Thank you a lot @sambhavnoobcoder for the fix and thank @dvrogozh for opening the issue 🙏 ❤️

@sambhavnoobcoder
Copy link
Contributor Author

These changes have been made as well . i'll gladly look into any more comments on this PR if any more improvements are required .

Copy link
Collaborator

@ydshieh ydshieh left a comment

Choose a reason for hiding this comment

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

Great, and thank you again for the prompt fix ❤️

@ydshieh ydshieh merged commit 8e67230 into huggingface:main Mar 17, 2025
9 checks passed
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.

4 participants