From 20d908395703b646e7a831bdcc26b977c8d3237a Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Wed, 6 May 2020 15:07:33 -0700 Subject: [PATCH] move repeated code into function --- features/environment.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/features/environment.py b/features/environment.py index e2fab73c..4843de45 100644 --- a/features/environment.py +++ b/features/environment.py @@ -2,6 +2,11 @@ import shutil import os import sys +def clean_all_working_dirs(): + for folder in ("configs", "journals", "cache"): + working_dir = os.path.join("features", folder) + if os.path.exists(working_dir): + shutil.rmtree(working_dir) def before_feature(context, feature): # add "skip" tag @@ -18,10 +23,7 @@ def before_feature(context, feature): def before_scenario(context, scenario): """Before each scenario, backup all config and journal test data.""" # Clean up in case something went wrong - for folder in ("configs", "journals", "cache"): - working_dir = os.path.join("features", folder) - if os.path.exists(working_dir): - shutil.rmtree(working_dir) + clean_all_working_dirs() for folder in ("configs", "journals"): original = os.path.join("features", "data", folder) @@ -48,7 +50,5 @@ def before_scenario(context, scenario): def after_scenario(context, scenario): """After each scenario, restore all test data and remove working_dirs.""" - for folder in ("configs", "journals", "cache"): - working_dir = os.path.join("features", folder) - if os.path.exists(working_dir): - shutil.rmtree(working_dir) + clean_all_working_dirs() +