@@ -491,6 +491,32 @@ def test_clear_cache_clears_other_lru_caches(self) -> None:
491
491
# less equal because the "baseline" might have had multiple calls to bootstrap()
492
492
self .assertLessEqual (cleared_cache .currsize , baseline_cache .currsize )
493
493
494
+ def test_file_cache_after_clear_cache (self ) -> None :
495
+ """Test to mimic the behavior of how pylint lints file and
496
+ ensure clear cache clears everything stored in the cache.
497
+ See https://github.com/pylint-dev/pylint/pull/9932#issuecomment-2364985551
498
+ for more information.
499
+ """
500
+ orig_sys_path = sys .path [:]
501
+ try :
502
+ search_path = resources .RESOURCE_PATH
503
+ sys .path .insert (0 , search_path )
504
+ node = astroid .MANAGER .ast_from_file (resources .find ("data/cache/a.py" ))
505
+ self .assertEqual (node .name , "cache.a" )
506
+
507
+ # This import from statement should succeed and update the astroid cache
508
+ importfrom_node = astroid .extract_node ("from cache import a" )
509
+ importfrom_node .do_import_module (importfrom_node .modname )
510
+ finally :
511
+ sys .path = orig_sys_path
512
+
513
+ astroid .MANAGER .clear_cache ()
514
+
515
+ importfrom_node = astroid .extract_node ("from cache import a" )
516
+ # Try import from again after clear cache, this should raise an error
517
+ with self .assertRaises (AstroidBuildingError ):
518
+ importfrom_node .do_import_module (importfrom_node .modname )
519
+
494
520
def test_brain_plugins_reloaded_after_clearing_cache (self ) -> None :
495
521
astroid .MANAGER .clear_cache ()
496
522
format_call = astroid .extract_node ("''.format()" )
0 commit comments