Skip to content

Commit 589b9d5

Browse files
committed
prefer pip packages over distro packages to fix runtime_version ImportError
Signed-off-by: Yijing Yan <yijingyan@microsoft.com>
1 parent f014fb3 commit 589b9d5

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

sonic-ycabled/tests/conftest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import site
2+
import sys
3+
4+
5+
def _prefer_newer_python_sites() -> None:
6+
"""Ensure test imports prefer user/local site-packages over distro site-packages."""
7+
preferred = []
8+
9+
try:
10+
preferred.append(site.getusersitepackages())
11+
except Exception:
12+
pass
13+
14+
for path in list(sys.path):
15+
if path.startswith("/usr/local/lib/python") and path.endswith("/dist-packages"):
16+
preferred.append(path)
17+
18+
ordered = []
19+
seen = set()
20+
for path in preferred:
21+
if path and path not in seen:
22+
ordered.append(path)
23+
seen.add(path)
24+
25+
for path in reversed(ordered):
26+
if path in sys.path:
27+
sys.path.remove(path)
28+
sys.path.insert(0, path)
29+
30+
31+
_prefer_newer_python_sites()

0 commit comments

Comments
 (0)