def test_modulepickling_change_cache_dir(monkeypatch, tmpdir):
 dir_1 = str(tmpdir.mkdir('first'))
 dir_2 = str(tmpdir.mkdir('second'))
 item_1 = ParserCacheItem('fake parser 1')
 item_2 = ParserCacheItem('fake parser 2')
 path_1 = 'fake path 1'
 path_2 = 'fake path 2'
 monkeypatch.setattr(settings, 'cache_directory', dir_1)
 ParserPickling.save_parser(path_1, item_1)
 cached = load_stored_item(ParserPickling, path_1, item_1)
 assert (cached == item_1.parser)
 monkeypatch.setattr(settings, 'cache_directory', dir_2)
 ParserPickling.save_parser(path_2, item_2)
 cached = load_stored_item(ParserPickling, path_1, item_1)
 assert (cached is None)

def test_modulepickling_change_cache_dir ( monkeypatch , tmpdir ) : dir_1 = str ( tmpdir . mkdir ( 'first' ) ) dir_2 = str ( tmpdir . mkdir ( 'second' ) ) item_1 = ParserCacheItem ( 'fake parser 1' ) item_2 = ParserCacheItem ( 'fake parser 2' ) path_1 = 'fake path 1' path_2 = 'fake path 2' monkeypatch . setattr ( settings , 'cache_directory' , dir_1 ) ParserPickling . save_parser ( path_1 , item_1 ) cached = load_stored_item ( ParserPickling , path_1 , item_1 ) assert ( cached == item_1 . parser ) monkeypatch . setattr ( settings , 'cache_directory' , dir_2 ) ParserPickling . save_parser ( path_2 , item_2 ) cached = load_stored_item ( ParserPickling , path_1 , item_1 ) assert ( cached is None )
parserpickling should not save old cache when cache_directory is changed .