Skip to content

Commit

Permalink
Merge pull request #4 from ctripcorp/feature_error_check
Browse files Browse the repository at this point in the history
Feature error check
  • Loading branch information
xiaoxiaocaiiao authored Jan 25, 2022
2 parents 8ed4599 + 3d0a96f commit afc8663
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
11 changes: 11 additions & 0 deletions flybirds/cli/parse_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def default_report_path():
return report_path


def check_workspace_args(feature_path):
base_dir = os.getcwd()
config_dir = os.path.join(base_dir, "config")

if os.path.isdir(config_dir) is False:
raise Exception(f"not find config directory in {base_dir}")


def parse_args(
feature_path, tag, report_format, report_path, define, rerun, es,
to_html, run_at
Expand All @@ -34,6 +42,9 @@ def parse_args(
f"flybirds cmd info: {feature_path} {tag} {report_format} {report_path}"
f" {define} {rerun} {es} {to_html} {run_at}"
)

check_workspace_args(feature_path)

use_define = []
tags = []
need_rerun = False
Expand Down
2 changes: 2 additions & 0 deletions flybirds/core/config_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def get_config(config, name):
c_f = file_helper.get_json_from_file(path)
if c_f.__contains__(name):
return c_f.get(name)
else:
raise Exception(f"not find path: {path}")
elif config.__contains__(name):
return config.get(name)

Expand Down
10 changes: 10 additions & 0 deletions flybirds/core/launch_cycle/run_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def exe(context):
cmd_str = context.get("cmd_str")
need_rerun_args = context.get("need_rerun_args")
report_dir_path = context.get("report_dir_path")
# cwd_pth = os.getcwd()
# if os.environ.get('base_dir') is not None:
# cwd_pth = os.environ.get('base_dir')

behave_process = subprocess.Popen(
cmd_str, cwd=os.getcwd(), shell=True, stdout=None
Expand All @@ -78,6 +81,13 @@ def exe(context):
behave_process.wait()
behave_process.communicate()

# if os.environ.get('base_dir') is not None:
# if report_dir_path is not None and os.path.isabs( \
# report_dir_path) is \
# False:
# report_dir_path = os.path.join(
# os.environ.get('base_dir'), report_dir_path)

# Determine whether the failed scenario needs to be re-run
rerun_launch(need_rerun_args, report_dir_path, run_args)

Expand Down
21 changes: 15 additions & 6 deletions flybirds/report/fail_feature_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ def rerun_launch(need_rerun_args, report_dir_path, run_args):
"rerun_report_dir_path"
)
if rerun_cmd_str is not None:
# cwd_pth = os.getcwd()
# if os.environ.get('base_dir') is not None:
# cwd_pth = os.environ.get('base_dir')
rerun_behave_process = subprocess.Popen(
rerun_cmd_str,
cwd=os.getcwd(),
Expand Down Expand Up @@ -221,8 +224,8 @@ def create_rerun(report_dir, rerun_dir, run_count, max_fail_count=1.0):
)
result = False
elif (
isinstance(max_fail_count, float)
and (fail_count / sum_count) > max_fail_count
isinstance(max_fail_count, float)
and (fail_count / sum_count) > max_fail_count
):
log.info(
"Feature to rerun after creation failure "
Expand Down Expand Up @@ -384,6 +387,12 @@ def copy_behave_need_file(rerun_root_dir):
"""
copy step.py and environment.py and other behave files to feature path
"""

# cwd_pth = os.getcwd()
# if os.environ.get('base_dir') is not None:
# cwd_pth = os.environ.get('base_dir')
# elif os.environ.get('base_feature_dir') is not None:
# cwd_pth = os.environ.get('base_feature_dir')
file_helper.create_dirs(os.path.join(rerun_root_dir, "steps"))
file_helper.clear_dirs(os.path.join(rerun_root_dir, "steps"))
shutil.copy(
Expand All @@ -407,8 +416,8 @@ def set_rerun_info(user_data, gr):
last_fail_scenario_info_obj = {}
# get rerun info, add into report
if (
"flybirdsAutoRerun" in user_data.keys()
and user_data["flybirdsAutoRerun"] == "Yes"
"flybirdsAutoRerun" in user_data.keys()
and user_data["flybirdsAutoRerun"] == "Yes"
):
log.info("this is rerun case execute")
rerun_info_array = user_data["flybirdsAutoRerunInfo"].split(",")
Expand All @@ -417,8 +426,8 @@ def set_rerun_info(user_data, gr):
rerun_info = item_rerun_info.strip()
print("rerun_info", rerun_info)
if (
"flybirdsAutoRerunInfo" in user_data.keys()
and os.path.exists(rerun_info)
"flybirdsAutoRerunInfo" in user_data.keys()
and os.path.exists(rerun_info)
):
try:
last_fail_scenario_info = (
Expand Down
4 changes: 4 additions & 0 deletions flybirds/report/gen/cucumber_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def gen(report_path):
cmd_str = f"node {gen_path} {report_path} {report_path}"
logger.info(f"report cmd:{cmd_str}")

# cwd_pth = os.getcwd()
# if os.environ.get('base_dir') is not None:
# cwd_pth = os.environ.get('base_dir')

report_process = subprocess.Popen(
cmd_str, cwd=os.getcwd(), shell=True, stdout=None
)
Expand Down
3 changes: 3 additions & 0 deletions flybirds/utils/file_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def clear_dirs(path):
"""
Clear all files and folders under a folder
"""
# cwd_pth = os.getcwd()
# if os.environ.get('base_dir') is not None:
# cwd_pth = os.environ.get('base_dir')
path = os.path.join(os.getcwd(), path)
if os.path.exists(path):
ls = os.listdir(path)
Expand Down

0 comments on commit afc8663

Please sign in to comment.