diff --git a/environment.py b/environment.py index 53b2a9f..541c97e 100644 --- a/environment.py +++ b/environment.py @@ -30,18 +30,18 @@ def before_scenario(context: PetStoreContext, scenario: Scenario): def after_scenario(context: PetStoreContext, scenario: Scenario): - if scenario.status == "failed": - scenario_error_dir = Path("logs") - scenario_error_dir.mkdir(exist_ok=True) - base_name = time.strftime("%Y-%m-%d_%H%M%S_{}".format(re.sub(r'[/\\:*?"<>#]', "", scenario.name)[:60])) - log_file_path = scenario_error_dir / "{}.txt".format(base_name) - for step in scenario.steps: - if step.status in ["failed", "undefined"]: - log_file_path.write_text( - "Scenario: {}\nStep: {} {}\nError Message: {}".format( - scenario.name, step.keyword, step.name, step.error_message - ) - ) - break - else: - log_file_path.write_text("Scenario: {}\nStep: N/A".format(scenario.name)) + if scenario.status != "failed": + return + scenario_error_dir = Path("logs") + scenario_error_dir.mkdir(exist_ok=True) + base_name = time.strftime("%Y-%m-%d_%H%M%S_{}".format(re.sub(r'[/\\:*?"<>#]', "", scenario.name)[:60])) + log_file_path = scenario_error_dir / f"{base_name}.txt" + for step in scenario.steps: + if step.status in ["failed", "undefined"]: + log_file_path.write_text( + f"Scenario: {scenario.name}\nStep: {step.keyword} {step.name}\nError Message: {step.error_message}" + ) + + break + else: + log_file_path.write_text(f"Scenario: {scenario.name}\nStep: N/A") diff --git a/petstore_swagger_bdd/browser.py b/petstore_swagger_bdd/browser.py index a9ab1ab..3fc4803 100644 --- a/petstore_swagger_bdd/browser.py +++ b/petstore_swagger_bdd/browser.py @@ -16,7 +16,7 @@ def chrome_options(): if not gpu: _chrome_options.add_argument("--disable-gpu") if window_size: - _chrome_options.add_argument("--window-size={}".format(window_size)) + _chrome_options.add_argument(f"--window-size={window_size}") if headless: _chrome_options.add_argument("--headless") _chrome_options.add_argument("--load-images=no") diff --git a/steps/petstore_api.py b/steps/petstore_api.py index e0020d2..5f07671 100644 --- a/steps/petstore_api.py +++ b/steps/petstore_api.py @@ -10,7 +10,7 @@ def step_impl_1(context: PetStoreContext, method: str, status: str): context.http_response = requests.request( method=method, - url=context.base_url + "/v2/pet/findByStatus?status={}".format(status), + url=context.base_url + f"/v2/pet/findByStatus?status={status}", ) @@ -33,7 +33,7 @@ def step_impl_4(context: PetStoreContext, method: str): raise ValueError("No value stored in context.pet_store_object.") requests.request( method=method, - url=context.base_url + "/v2/pet/{}".format(context.pet_store_object["id"]), + url=context.base_url + f'/v2/pet/{context.pet_store_object["id"]}', )