mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-28 13:36:14 +02:00
Make sure testing cleans up after itself (#940)
This adds the ability to run commands in a cache directory without the test writer knowing where the cache directory is located. This will let us expand later if we want to start using system temp folders, without having to rewrite any of our tests. * clean up extra directories after running behave * clean up white space issues * move repeated code into function * clean up behave code for creating cache directories * Fix for windows shell parsing in our test suite Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
This commit is contained in:
parent
c5f40f1d15
commit
ecb4562c29
5 changed files with 68 additions and 43 deletions
|
@ -3,6 +3,13 @@ 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
|
||||
# https://stackoverflow.com/a/42721605/4276230
|
||||
|
@ -18,10 +25,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"):
|
||||
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 +52,4 @@ 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"):
|
||||
working_dir = os.path.join("features", folder)
|
||||
if os.path.exists(working_dir):
|
||||
shutil.rmtree(working_dir)
|
||||
clean_all_working_dirs()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue