Skip to content

Commit 79d9c93

Browse files
committed
add feature to mock class that block startup
1 parent 391ff8f commit 79d9c93

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

generator/main.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import sys
2-
import json
3-
import click
1+
import sys, json, click, mock
42
from fastapi import FastAPI
53
from uvicorn.importer import import_from_string
64
from generator.lib.exceptions import NotFastAPIException
@@ -29,9 +27,19 @@
2927
show_default=True,
3028
help="The name the openapi file will assume."
3129
)
32-
def main(app, app_dir, output_dir, file_name):
30+
@click.option(
31+
"--mock-class",
32+
"classes_to_mock",
33+
multiple=True,
34+
help="Use it to mock a package that is not usefully for the openapi generation and block the fastapi start"
35+
)
36+
def main(app, app_dir, output_dir, file_name, classes_to_mock):
3337
sys.path.insert(0, app_dir)
3438

39+
if classes_to_mock:
40+
for class_to_mock in classes_to_mock:
41+
mock.patch(class_to_mock).start()
42+
3543
fastapi: FastAPI = import_from_string(app)
3644

3745
if not isinstance(fastapi, FastAPI):

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
click==7.1.2
22
uvicorn==0.13.3
3-
fastapi==0.63.0
3+
fastapi==0.63.0
4+
mock==4.0.3

0 commit comments

Comments
 (0)