move repeated code into function

This commit is contained in:
Jonathan Wren 2020-05-06 15:07:33 -07:00
parent e22b758e41
commit 20d9083957

View file

@ -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()