From cf3483e752def6d54b4f65b49599fc50583a967c Mon Sep 17 00:00:00 2001 From: Olivier Bourdon Date: Tue, 13 Nov 2018 12:16:49 +0100 Subject: [PATCH] Add tests filters (#43221) This will allow tests to be carried out condtionally if necessary using regexp include and/or exclude filters Reorganize imports into alphabetical order for easier insertion --- .../interfaces_file/test_interfaces_file.py | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/test/units/modules/system/interfaces_file/test_interfaces_file.py b/test/units/modules/system/interfaces_file/test_interfaces_file.py index 940feb9bd1..cb8c06c1ad 100644 --- a/test/units/modules/system/interfaces_file/test_interfaces_file.py +++ b/test/units/modules/system/interfaces_file/test_interfaces_file.py @@ -17,14 +17,15 @@ from units.compat import unittest from ansible.modules.system import interfaces_file -import os -import json -import io -import inspect from shutil import copyfile, move import difflib -import tempfile +import inspect +import io +import json +import os +import re import shutil +import tempfile class AnsibleFailJson(Exception): @@ -50,8 +51,13 @@ golden_output_path = os.path.join(os.path.dirname(__file__), 'fixtures', 'golden class TestInterfacesFileModule(unittest.TestCase): - def getTestFiles(self): - return next(os.walk(fixture_path))[2] + def getTestFiles(self, include_filter=None, exclude_filter=None): + flist = next(os.walk(fixture_path))[2] + if include_filter: + flist = filter(lambda x: re.match(include_filter, x), flist) + if exclude_filter: + flist = filter(lambda x: not re.match(exclude_filter, x), flist) + return flist def compareFileToBackup(self, path, backup): with open(path) as f1: