From 6491e53fa1b01c9d14179a58340f16781c2131ab Mon Sep 17 00:00:00 2001 From: Jan Fajerski Date: Wed, 12 Aug 2020 12:58:29 +0200 Subject: [PATCH] pybind/mgr/snap_schedule: fix imports for snap_schedule vs mgr wide tox runs Signed-off-by: Jan Fajerski --- src/pybind/mgr/snap_schedule/__init__.py | 5 ++++- src/pybind/mgr/snap_schedule/fs/schedule.py | 5 ++++- src/pybind/mgr/snap_schedule/tox.ini | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pybind/mgr/snap_schedule/__init__.py b/src/pybind/mgr/snap_schedule/__init__.py index 843b447f54071..8001b7184851d 100644 --- a/src/pybind/mgr/snap_schedule/__init__.py +++ b/src/pybind/mgr/snap_schedule/__init__.py @@ -2,7 +2,10 @@ from os import environ -if 'UNITTEST' in environ: +if 'SNAP_SCHED_UNITTEST' in environ: import tests +elif 'UNITTEST' in environ: + import tests + from .module import Module else: from .module import Module diff --git a/src/pybind/mgr/snap_schedule/fs/schedule.py b/src/pybind/mgr/snap_schedule/fs/schedule.py index cee7a3c763d9c..019d28caa2d39 100644 --- a/src/pybind/mgr/snap_schedule/fs/schedule.py +++ b/src/pybind/mgr/snap_schedule/fs/schedule.py @@ -14,6 +14,9 @@ from typing import Tuple, Any log = logging.getLogger(__name__) +TESTING = 'SNAP_SCHED_TESTING' in environ + + # Work around missing datetime.fromisoformat for < python3.7 SNAP_DB_TS_FORMAT = '%Y-%m-%dT%H:%M:%S' try: @@ -354,7 +357,7 @@ class Schedule(object): def repeat(self): mult = self.schedule[-1] period = int(self.schedule[0:-1]) - if 'SNAP_SCHED_TESTING' in environ and mult == 'M': + if TESTING and mult == 'M': return period * 60 elif mult == 'h': return period * 60 * 60 diff --git a/src/pybind/mgr/snap_schedule/tox.ini b/src/pybind/mgr/snap_schedule/tox.ini index 756dc044bdcd8..fbf894b068eec 100644 --- a/src/pybind/mgr/snap_schedule/tox.ini +++ b/src/pybind/mgr/snap_schedule/tox.ini @@ -10,7 +10,7 @@ setenv= PATH = {toxinidir}/../../../../build/bin:$PATH py27: PYTHONPATH = {toxinidir}/../../../../build/lib/cython_modules/lib.2:.. py3: PYTHONPATH = {toxinidir}/../../../../build/lib/cython_modules/lib.3:{toxinidir} - UNITTEST = true + SNAP_SCHED_UNITTEST = true deps = pytest mock -- 2.47.3