From b1dd3d6787a136ad2dfd5876c94bb9badaa3d912 Mon Sep 17 00:00:00 2001 From: Lukas Puehringer Date: Tue, 18 Aug 2020 15:55:43 +0200 Subject: [PATCH] Skip api tests on Python < 3.6 The new metadata module uses constructs that are only available on Python >= 3.6 (typing, f-format strings, etc.). Signed-off-by: Lukas Puehringer --- tests/test_api.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index 42db3524..3fdac39b 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -3,7 +3,10 @@ # Copyright 2020, New York University and the TUF contributors # SPDX-License-Identifier: MIT OR Apache-2.0 """ Unit tests for api/metdata.py + """ + +import sys import logging import os import shutil @@ -13,10 +16,21 @@ from datetime import timedelta from dateutil.relativedelta import relativedelta -from tuf.api.metadata import ( - Snapshot, - Timestamp, -) +# TODO: Remove case handling when fully dropping support for versions >= 3.6 +IS_PY_VERSION_SUPPORTED = sys.version_info >= (3, 6) + +# Use setUpModule to tell unittest runner to skip this test module gracefully. +def setUpModule(): + if not IS_PY_VERSION_SUPPORTED: + raise unittest.SkipTest("requires Python 3.6 or higher") + +# Since setUpModule is called after imports we need to import conditionally. +if IS_PY_VERSION_SUPPORTED: + from tuf.api.metadata import ( + Snapshot, + Timestamp, + ) + logger = logging.getLogger(__name__)