From 65880baf3ee9d2f09eeb24a82e40dc581088b9f0 Mon Sep 17 00:00:00 2001 From: Jamal Date: Fri, 14 Apr 2023 12:17:41 +0300 Subject: [PATCH] Add DEBUG_MODE option --- README.md | 1 + setup.py | 2 +- swagger_coverage_py/configs.py | 2 ++ swagger_coverage_py/reporter.py | 10 +++++++--- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0fff38f..752516b 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ API_DOCS_TYPE="swagger" # Note: "openapi" is default type of API docs API_DOCS_VERSION="2.0" # Note: "3.0.0" is default version of API docs API_DOCS_FORMAT="yaml" # Note: "json" is default format of API docs and output files API_COVERAGE_REPORTS_DISABLED=True # Skip requests recording. No files will be saved to 'swagger-coverage-output' dir +DEBUG_MODE=True # Enable debug mode. All commandline logs will be printed to console (False by default) ``` diff --git a/setup.py b/setup.py index 72fc7ee..a9f6c4f 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="swagger-coverage", - version="3.0.0", + version="3.1.0", author="Jamal Zeinalov", author_email="jamal.zeynalov@gmail.com", description='Python adapter for "swagger-coverage" tool', diff --git a/swagger_coverage_py/configs.py b/swagger_coverage_py/configs.py index 190d370..b1143ae 100644 --- a/swagger_coverage_py/configs.py +++ b/swagger_coverage_py/configs.py @@ -10,3 +10,5 @@ API_DOCS_VERSION = env.str("API_DOCS_VERSION", default="3.0.0") # "2.0" API_DOCS_FORMAT = env.str("API_DOCS_FORMAT", default="json") # "yaml" IS_DISABLED = env.bool("API_COVERAGE_REPORTS_DISABLED", default=False) # If True then requests won't be recorded + +DEBUG_MODE = env.bool("DEBUG_MODE", default=False) # Set to True to see commandline output diff --git a/swagger_coverage_py/reporter.py b/swagger_coverage_py/reporter.py index cf06bea..59fb536 100644 --- a/swagger_coverage_py/reporter.py +++ b/swagger_coverage_py/reporter.py @@ -2,16 +2,17 @@ import platform import re import shutil +import subprocess from pathlib import Path import requests -from swagger_coverage_py.configs import API_DOCS_FORMAT +from swagger_coverage_py.configs import API_DOCS_FORMAT, DEBUG_MODE from swagger_coverage_py.docs_writers.api_doc_writer import write_api_doc_to_file class CoverageReporter: - def __init__(self, api_name: str, host: str, verify:bool = True): + def __init__(self, api_name: str, host: str, verify: bool = True): self.host = host self.verify = verify self.swagger_doc_file = f"swagger-doc-{api_name}.{API_DOCS_FORMAT}" @@ -64,7 +65,10 @@ def generate_report(self): command if platform.system() != "Windows" else command.replace("/", "\\") ) - os.system(command) + # Suppress all output if not in debug mode + command = command + " > /dev/null 2>&1" if not DEBUG_MODE else command + + subprocess.run(command, shell=True) def cleanup_input_files(self): shutil.rmtree(self.output_dir, ignore_errors=True)