Skip to content

Commit

Permalink
Merge pull request #22 from JamalZeynalov/18-add-option-to-suppress-o…
Browse files Browse the repository at this point in the history
…utput-of-coveragereportergenerate_report

Add DEBUG_MODE option
  • Loading branch information
JamalZeynalov authored Apr 14, 2023
2 parents a566b56 + 65880ba commit d46db1d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="swagger-coverage",
version="3.0.0",
version="3.1.0",
author="Jamal Zeinalov",
author_email="[email protected]",
description='Python adapter for "swagger-coverage" tool',
Expand Down
2 changes: 2 additions & 0 deletions swagger_coverage_py/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 7 additions & 3 deletions swagger_coverage_py/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d46db1d

Please sign in to comment.