File tree Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ requires-python = ">=3.7"
3131dependencies = [
3232 " pytest>=7.0" ,
3333 " pexpect>=4.4" ,
34+ " filelock>=3.12.2"
3435]
3536
3637[project .urls ]
Original file line number Diff line number Diff line change 1717from collections import Counter
1818from operator import itemgetter
1919
20+ import filelock
2021import pytest
2122from _pytest .config import Config
2223from _pytest .fixtures import (
@@ -625,18 +626,20 @@ def cache_dir(request: FixtureRequest) -> str:
625626def port_target_cache (cache_dir ) -> t .Dict [str , str ]:
626627 """Session scoped port-target cache, for esp only"""
627628 _cache_file_path = os .path .join (cache_dir , 'port_target_cache' )
629+ lock = filelock .FileLock (f'{ _cache_file_path } .lock' )
628630 resp : t .Dict [str , str ] = {}
629- try :
630- with shelve .open (_cache_file_path ) as f :
631- resp = dict (f )
632- except dbm .error :
633- os .remove (_cache_file_path )
631+ with lock :
632+ try :
633+ with shelve .open (_cache_file_path ) as f :
634+ resp = dict (f )
635+ except dbm .error :
636+ os .remove (_cache_file_path )
634637
635638 yield resp
636-
637- with shelve .open (_cache_file_path ) as f :
638- for k , v in resp .items ():
639- f [k ] = v
639+ with lock :
640+ with shelve .open (_cache_file_path ) as f :
641+ for k , v in resp .items ():
642+ f [k ] = v
640643
641644
642645@pytest .fixture (scope = 'session' )
You can’t perform that action at this time.
0 commit comments