From 59a2d7410705eaa5315e4ea11325cce74ce4067e Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Fri, 7 Jul 2023 16:12:19 +1200 Subject: [PATCH] pytests: add helper to grab a directory from environment Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- python/samba/tests/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/python/samba/tests/__init__.py b/python/samba/tests/__init__.py index f117d0b1341..09c70aab134 100644 --- a/python/samba/tests/__init__.py +++ b/python/samba/tests/__init__.py @@ -704,3 +704,19 @@ def check_help_consistency(out, if errors: return "\n".join(errors) + + +def get_env_dir(key): + """A helper to pull a directory name from the environment, used in + some tests that optionally write e.g. fuzz seeds into a directory + named in an environment valiable. + """ + dir = os.environ.get(key) + if dir is None: + return None + + if not os.path.isdir(dir): + raise ValueError( + f"{key} should name an existing directory (got '{dir}')") + + return dir -- 2.11.4.GIT