Skip to content

Commit

Permalink
feat: use endpoint value from workflow dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Van-QA authored and Van-QA committed May 20, 2024
1 parent 8d4a8a7 commit 4502757
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/jan-openai-api-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 5,7 @@ on:
endpoints:
description: 'comma-separated list (see available at endpoints_mapping.json e.g. GET /users,POST /transform)'
required: false
default: none
default: All
type: string

push:
Expand Down Expand Up @@ -75,14 75,8 @@ jobs:
cat ../docs/tests/endpoints_mapping.json >> tests/endpoints_mapping.json
# start mock server and run test then stop mock server
IFS=',' read -ra endpoints <<< "$ENDPOINTS"
markers=""
for endpoint in "${endpoints[@]}"; do
markers ="endpoint($endpoint) or "
done
markers=${markers% or }
prism mock ../docs/openapi/jan.yaml > prism.log & prism_pid=$! &&
pytest -k "$markers" --reportportal --html=report.html && kill $prism_pid
pytest --endpoint "$ENDPOINTS" --reportportal --html=report.html && kill $prism_pid
deactivate
env:
ENDPOINTS: ${{ github.event.inputs.endpoints }}
Expand Down
14 changes: 11 additions & 3 deletions docs/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,18 1,26 @@
import json


def pytest_addoption(parser):
parser.addoption("--endpoint", action="store", default="all", help="my option: endpoints")
parser.addoption(
"--endpoint", action="store", default="all", help="my option: endpoints"
)


def pytest_configure(config):
config.addinivalue_line("markers", "endpoint(endpoint): this mark select the test based on endpoint")
config.addinivalue_line(
"markers", "endpoint(endpoint): this mark select the test based on endpoint"
)


def pytest_runtest_setup(item):
getoption = item.config.getoption("--endpoint").split(',')
getoption = item.config.getoption("--endpoint").split(",")
if getoption != ["all"]:
endpoint_names = [mark.args[0] for mark in item.iter_markers(name="endpoint")]
if not endpoint_names or not set(getoption).intersection(set(endpoint_names)):
pytest.skip("Test skipped because endpoint is {!r}".format(endpoint_names))


def pytest_collection_modifyitems(items):
# load the JSON file
with open("tests/endpoints_mapping.json", "r") as json_file:
Expand Down

0 comments on commit 4502757

Please sign in to comment.