From 56f517606036832a56ff9f650fe2256e26c54e06 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Wed, 6 Jul 2022 19:14:58 -0300 Subject: [PATCH] Fixed problems when running tests and a copy of KiBot is in ~/.local --- tests/test_plot/__init__.py | 7 ++++++- tests/utils/context.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/test_plot/__init__.py b/tests/test_plot/__init__.py index e2c5b0aa..415a1233 100644 --- a/tests/test_plot/__init__.py +++ b/tests/test_plot/__init__.py @@ -8,5 +8,10 @@ if prev_dir not in sys.path: # Utils import from utils import context # noqa: F401 prev_dir = os.path.dirname(prev_dir) -if prev_dir not in sys.path: +# py-test inserts things at the beginning, so we could end loading an installed copy of KiBot +if sys.path[0] != prev_dir: + try: + sys.path.remove(prev_dir) + except ValueError: + pass sys.path.insert(0, prev_dir) diff --git a/tests/utils/context.py b/tests/utils/context.py index bbc35320..d76cc3a6 100644 --- a/tests/utils/context.py +++ b/tests/utils/context.py @@ -11,7 +11,12 @@ from glob import glob from pty import openpty import xml.etree.ElementTree as ET prev_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -if prev_dir not in sys.path: +# py-test inserts things at the beginning, so we could end loading an installed copy of KiBot +if sys.path[0] != prev_dir: + try: + sys.path.remove(prev_dir) + except ValueError: + pass sys.path.insert(0, prev_dir) from kibot.misc import (error_level_to_name)