From 69899ef59878551391259db1a73ee699d3d44e74 Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 21:32:49 +0900 Subject: [PATCH 01/21] test: create test and CI --- .github/workflows/ci.yml | 62 +++++++++++++++++++++++++++++++++++ src/poetry.lock | 2 +- src/pyproject.toml | 1 + src/pytest_report.xml | 1 + src/test/feature/__init__.py | 0 src/test/unit/__init__.py | 0 src/test/unit/test_example.py | 13 ++++++++ 7 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml create mode 100644 src/pytest_report.xml create mode 100644 src/test/feature/__init__.py create mode 100644 src/test/unit/__init__.py create mode 100644 src/test/unit/test_example.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..dd27f48 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,62 @@ +name: CI + +on: + pull_request: + +permissions: + contents: read + pull-requests: write + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker Compose + run: | + docker-compose up -d + + - name: Run tests (inside Docker) + run: | + docker-compose exec fastapi_server pytest /code/test/ --junitxml=/code/pytest_report.xml + + - name: Install Node.js and xml2js + uses: actions/setup-node@v3 + with: + node-version: '16' + + - name: Install xml2js + run: | + npm install xml2js + + - name: Report test results + if: failure() + uses: actions/github-script@v6 + with: + script: | + const fs = require('fs'); + const xml2js = require('xml2js'); + const core = require('@actions/core'); + const parser = new xml2js.Parser(); + const xml = fs.readFileSync('src/pytest_report.xml', 'utf8'); + parser.parseString(xml, (err, result) => { + if (err) { + core.setFailed('Failed to parse XML'); + return; + } + const failures = result.testsuite.testcase.filter(tc => tc.failure); + let commentBody = '## :x: Tests failed\n'; + failures.forEach(tc => { + commentBody += `### ${tc.$.classname}::${tc.$.name}\n`; + commentBody += `\`\`\`\n${tc.failure[0]._}\n\`\`\`\n`; + }); + github.rest.issues.createComment({ + issue_number: context.payload.pull_request.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: commentBody + }); + }); diff --git a/src/poetry.lock b/src/poetry.lock index f00d80f..4297542 100644 --- a/src/poetry.lock +++ b/src/poetry.lock @@ -1671,4 +1671,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = ">=3.10,<3.12" -content-hash = "028ed7065abe88027ea3b0ada049730cb2390851664ecab2f4a3091f0bb3a592" +content-hash = "5b6deb5f6449b12d85e723c69940d04210c5fb138f64884541ed8770fddad8f9" diff --git a/src/pyproject.toml b/src/pyproject.toml index c3233ec..0b763a7 100644 --- a/src/pyproject.toml +++ b/src/pyproject.toml @@ -41,6 +41,7 @@ fastapi = {extras = ["all"], version = "^0.115.0"} fastapi-pagination = {extras = ["sqlalchemy"], version = "^0.12.27"} asyncer = "^0.0.8" httpx = "^0.27.2" +pytest = "^8.3.3" [tool.ruff.per-file-ignores] "__init__.py" = [ "F401",] diff --git a/src/pytest_report.xml b/src/pytest_report.xml new file mode 100644 index 0000000..c4c0b43 --- /dev/null +++ b/src/pytest_report.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/test/feature/__init__.py b/src/test/feature/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/test/unit/__init__.py b/src/test/unit/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/test/unit/test_example.py b/src/test/unit/test_example.py new file mode 100644 index 0000000..41dc27a --- /dev/null +++ b/src/test/unit/test_example.py @@ -0,0 +1,13 @@ +from fastapi.testclient import TestClient +from app.main import app + +client = TestClient(app) + + +def test_root_endpoint(): + expected_response = {"message": "Hello World"} + + response = client.get("/") + + assert response.status_code == 200 + assert response.json() == expected_response From 22b1d2cb353da67e7e9e482ed9010fd735ddc81a Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 21:42:43 +0900 Subject: [PATCH 02/21] test: change from Docker to Poetry --- .github/workflows/ci.yml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd27f48..c431a0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,13 +15,25 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Set up Docker Compose - run: | - docker-compose up -d + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: '3.11' + architecture: 'x64' + + - name: Install dependencies + run: pip install poetry + + - name: Setup poetry project + run: poetry install - name: Run tests (inside Docker) run: | - docker-compose exec fastapi_server pytest /code/test/ --junitxml=/code/pytest_report.xml + pytest src/test --junitxml=pytest_report.xml + continue-on-error: true + - name: Install Node.js and xml2js uses: actions/setup-node@v3 From bfedba6660b4deed431ea56305c7c13b5c80c0cf Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 21:46:15 +0900 Subject: [PATCH 03/21] test: fix drop the test --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c431a0d..10f312b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,9 @@ jobs: - uses: actions/checkout@v2 + - name: Move to python workspace + run: cd src + - name: Setup Python uses: actions/setup-python@v2 with: From f1fd9a840993997904adb7d9c0773e37ec742f61 Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 21:53:02 +0900 Subject: [PATCH 04/21] test: fix drop the test --- .github/workflows/ci.yml | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10f312b..78f4de3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,28 +15,26 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - uses: actions/checkout@v2 - - - name: Move to python workspace - run: cd src - - name: Setup Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: '3.11' - architecture: 'x64' - name: Install dependencies - run: pip install poetry + working-directory: ./src + run: | + pip install poetry + poetry install - - name: Setup poetry project - run: poetry install + - name: Set up Docker Compose + working-directory: ./src + run: docker-compose up -d - name: Run tests (inside Docker) + working-directory: ./src run: | - pytest src/test --junitxml=pytest_report.xml - continue-on-error: true - + docker-compose exec fastapi_server pytest /code/test/ --junitxml=/code/pytest_report.xml + docker cp ${CONTAINER_ID}:/code/pytest_report.xml pytest_report.xml - name: Install Node.js and xml2js uses: actions/setup-node@v3 @@ -44,11 +42,11 @@ jobs: node-version: '16' - name: Install xml2js - run: | - npm install xml2js + working-directory: ./src + run: npm install xml2js - name: Report test results - if: failure() + working-directory: ./src uses: actions/github-script@v6 with: script: | @@ -56,7 +54,7 @@ jobs: const xml2js = require('xml2js'); const core = require('@actions/core'); const parser = new xml2js.Parser(); - const xml = fs.readFileSync('src/pytest_report.xml', 'utf8'); + const xml = fs.readFileSync('pytest_report.xml', 'utf8'); parser.parseString(xml, (err, result) => { if (err) { core.setFailed('Failed to parse XML'); From 0082fb1ee46be95e8cdcd630ebbaa382b40bdac1 Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 22:00:47 +0900 Subject: [PATCH 05/21] test: change test report script --- .github/workflows/ci.yml | 48 +++++----------------------------------- 1 file changed, 5 insertions(+), 43 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78f4de3..8ab5aad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,50 +26,12 @@ jobs: pip install poetry poetry install - - name: Set up Docker Compose - working-directory: ./src - run: docker-compose up -d - - name: Run tests (inside Docker) working-directory: ./src - run: | - docker-compose exec fastapi_server pytest /code/test/ --junitxml=/code/pytest_report.xml - docker cp ${CONTAINER_ID}:/code/pytest_report.xml pytest_report.xml - - - name: Install Node.js and xml2js - uses: actions/setup-node@v3 - with: - node-version: '16' - - - name: Install xml2js - working-directory: ./src - run: npm install xml2js + run: pytest ./test/ --junitxml=/pytest_report.xml - - name: Report test results - working-directory: ./src - uses: actions/github-script@v6 + - name: Publish Test Report + uses: mikepenz/action-junit-report@v4 + if: failure() with: - script: | - const fs = require('fs'); - const xml2js = require('xml2js'); - const core = require('@actions/core'); - const parser = new xml2js.Parser(); - const xml = fs.readFileSync('pytest_report.xml', 'utf8'); - parser.parseString(xml, (err, result) => { - if (err) { - core.setFailed('Failed to parse XML'); - return; - } - const failures = result.testsuite.testcase.filter(tc => tc.failure); - let commentBody = '## :x: Tests failed\n'; - failures.forEach(tc => { - commentBody += `### ${tc.$.classname}::${tc.$.name}\n`; - commentBody += `\`\`\`\n${tc.failure[0]._}\n\`\`\`\n`; - }); - github.rest.issues.createComment({ - issue_number: context.payload.pull_request.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: commentBody - }); - }); + report_paths: '/pytest_report.xml' From 399420c00c4790c4be37914a94402f093879459e Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 22:06:16 +0900 Subject: [PATCH 06/21] test: FastAPI to be started in the background --- .github/workflows/ci.yml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ab5aad..d73a5b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,12 +26,25 @@ jobs: pip install poetry poetry install - - name: Run tests (inside Docker) + - name: Start FastAPI working-directory: ./src - run: pytest ./test/ --junitxml=/pytest_report.xml + run: | + poetry run uvicorn app:app --host 0.0.0.0 --port 8000 & + + - name: Run tests + working-directory: ./src + run: | + sleep 5 # Wait a bit for the server to be fully up and running + poetry run pytest ./test/ - name: Publish Test Report uses: mikepenz/action-junit-report@v4 if: failure() with: - report_paths: '/pytest_report.xml' + report_paths: 'pytest_report.xml' + + - name: Shutdown FastAPI + if: always() + working-directory: ./src + run: | + curl -X POST http://localhost:8000/shutdown From 1a862d7f2ce3da1c838164eab931f27a4fa72fff Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 22:14:43 +0900 Subject: [PATCH 07/21] test: set BACKEND_CORS_ORIGINS value --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d73a5b5..1af4fd5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,8 @@ jobs: - name: Run tests working-directory: ./src + env: + BACKEND_CORS_ORIGINS: '["http://localhost","https://example.com"]' run: | sleep 5 # Wait a bit for the server to be fully up and running poetry run pytest ./test/ From 4d9d0cfd4edd6645bbcf9f06b580af9a61821508 Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 22:17:25 +0900 Subject: [PATCH 08/21] test: cleanup unnecessary code --- .github/workflows/ci.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1af4fd5..38787e0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,9 +44,3 @@ jobs: if: failure() with: report_paths: 'pytest_report.xml' - - - name: Shutdown FastAPI - if: always() - working-directory: ./src - run: | - curl -X POST http://localhost:8000/shutdown From db0a11f330d80c45c46b6ca38ff7a02c39ef116d Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 22:21:13 +0900 Subject: [PATCH 09/21] test: Test for errors to check CI behavior --- src/test/unit/test_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/unit/test_example.py b/src/test/unit/test_example.py index 41dc27a..8c5ff16 100644 --- a/src/test/unit/test_example.py +++ b/src/test/unit/test_example.py @@ -9,5 +9,5 @@ def test_root_endpoint(): response = client.get("/") - assert response.status_code == 200 + assert response.status_code == 500 assert response.json() == expected_response From 1a3e465baf7ffd652ad2036f900c6d64a05e8aa5 Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 22:26:18 +0900 Subject: [PATCH 10/21] test: change report script --- .github/workflows/ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38787e0..223b84f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,10 @@ jobs: poetry run pytest ./test/ - name: Publish Test Report - uses: mikepenz/action-junit-report@v4 + uses: dorny/test-reporter@v1 if: failure() with: - report_paths: 'pytest_report.xml' + name: 'Test Report' + path: 'pytest_report.xml' + reporter: 'java-junit' + fail-on-error: false From 02138f53e78a8579155bdb5f399e2210b054bfa9 Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 22:36:06 +0900 Subject: [PATCH 11/21] test: fix reporting log path --- .github/workflows/ci.yml | 4 ++-- src/logs/.gitignore | 2 ++ src/pytest_report.xml | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 src/logs/.gitignore delete mode 100644 src/pytest_report.xml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 223b84f..c12e1b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,13 +37,13 @@ jobs: BACKEND_CORS_ORIGINS: '["http://localhost","https://example.com"]' run: | sleep 5 # Wait a bit for the server to be fully up and running - poetry run pytest ./test/ + poetry run pytest ./test/ --junitxml=./logs/pytest_report.xml - name: Publish Test Report uses: dorny/test-reporter@v1 if: failure() with: name: 'Test Report' - path: 'pytest_report.xml' + path: './src/logs/pytest_report.xml' reporter: 'java-junit' fail-on-error: false diff --git a/src/logs/.gitignore b/src/logs/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/src/logs/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/src/pytest_report.xml b/src/pytest_report.xml deleted file mode 100644 index c4c0b43..0000000 --- a/src/pytest_report.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file From c9725b897af4dafbefd42fa673ad19b9cd41dafd Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 22:41:50 +0900 Subject: [PATCH 12/21] test: Run the test again --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c12e1b2..0b6736f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,3 +47,4 @@ jobs: path: './src/logs/pytest_report.xml' reporter: 'java-junit' fail-on-error: false + \ No newline at end of file From de9df3a21f1a7a53956f8c4fb4b9bb6ff30ddb2c Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 22:46:01 +0900 Subject: [PATCH 13/21] test: grant permission to write on PR --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b6736f..5718042 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,8 @@ permissions: jobs: build: + permissions: + pull-requests: write runs-on: ubuntu-latest steps: @@ -47,4 +49,3 @@ jobs: path: './src/logs/pytest_report.xml' reporter: 'java-junit' fail-on-error: false - \ No newline at end of file From a57899c94259e43ba62e8fb2fc4adf32eeda282f Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 22:48:55 +0900 Subject: [PATCH 14/21] test: add write permissions to the check run --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5718042..2b5c102 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,11 +6,14 @@ on: permissions: contents: read pull-requests: write + checks: write jobs: build: permissions: + contents: read pull-requests: write + checks: write runs-on: ubuntu-latest steps: From de52310ec113ea789f988e9f7fb0f044bd54294b Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 22:57:12 +0900 Subject: [PATCH 15/21] test: merge the job and enhance action visibility --- .github/workflows/ci.yml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b5c102..6355af6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,22 +31,15 @@ jobs: pip install poetry poetry install - - name: Start FastAPI - working-directory: ./src - run: | - poetry run uvicorn app:app --host 0.0.0.0 --port 8000 & - - - name: Run tests + - name: Run tests and Publish Test Report working-directory: ./src env: BACKEND_CORS_ORIGINS: '["http://localhost","https://example.com"]' run: | sleep 5 # Wait a bit for the server to be fully up and running - poetry run pytest ./test/ --junitxml=./logs/pytest_report.xml - - - name: Publish Test Report + poetry run pytest ./test/ --junitxml=./logs/pytest_report.xml || true + echo "Publishing Test Report" uses: dorny/test-reporter@v1 - if: failure() with: name: 'Test Report' path: './src/logs/pytest_report.xml' From 3907039505d5b070c3253f47d864ce6e8165f73a Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 22:59:34 +0900 Subject: [PATCH 16/21] test: restore the required code --- .github/workflows/ci.yml | 7 ++++++- src/test/unit/test_example.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6355af6..7ca81cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,10 +31,15 @@ jobs: pip install poetry poetry install + - name: Start FastAPI + working-directory: ./src + run: | + poetry run uvicorn app:app --host 0.0.0.0 --port 8000 & + - name: Run tests and Publish Test Report working-directory: ./src env: - BACKEND_CORS_ORIGINS: '["http://localhost","https://example.com"]' + BACKEND_CORS_ORIGINS: '["*"]' run: | sleep 5 # Wait a bit for the server to be fully up and running poetry run pytest ./test/ --junitxml=./logs/pytest_report.xml || true diff --git a/src/test/unit/test_example.py b/src/test/unit/test_example.py index 8c5ff16..41dc27a 100644 --- a/src/test/unit/test_example.py +++ b/src/test/unit/test_example.py @@ -9,5 +9,5 @@ def test_root_endpoint(): response = client.get("/") - assert response.status_code == 500 + assert response.status_code == 200 assert response.json() == expected_response From 84eec4d40caceda88f5a3e729ff8d1eec3ecf2ce Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 23:02:27 +0900 Subject: [PATCH 17/21] test: merge the job and enhance action visibility --- .github/workflows/ci.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ca81cc..ce40bfa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,9 +44,6 @@ jobs: sleep 5 # Wait a bit for the server to be fully up and running poetry run pytest ./test/ --junitxml=./logs/pytest_report.xml || true echo "Publishing Test Report" - uses: dorny/test-reporter@v1 - with: - name: 'Test Report' - path: './src/logs/pytest_report.xml' - reporter: 'java-junit' - fail-on-error: false + curl -sSL https://github.com/dorny/test-reporter/releases/latest/download/test-reporter-linux -o test-reporter + chmod +x test-reporter + ./test-reporter -n 'Test Report' -p './logs/pytest_report.xml' -r 'java-junit' || true From 251d7614ccf75d0861eb35466415b9f233ddfe76 Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 23:06:59 +0900 Subject: [PATCH 18/21] test: upgrade actions/checkout@v3 to v4 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce40bfa..6e5b288 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Python uses: actions/setup-python@v4 From 27b7bd4c17d4b2351ee78c7207665df99e0eb7ae Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 23:08:04 +0900 Subject: [PATCH 19/21] test: test for errors to check CI behavior --- src/test/unit/test_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/unit/test_example.py b/src/test/unit/test_example.py index 41dc27a..8c5ff16 100644 --- a/src/test/unit/test_example.py +++ b/src/test/unit/test_example.py @@ -9,5 +9,5 @@ def test_root_endpoint(): response = client.get("/") - assert response.status_code == 200 + assert response.status_code == 500 assert response.json() == expected_response From afee43171b2d86237b5dc7dd76a12266d20d5752 Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 23:14:52 +0900 Subject: [PATCH 20/21] test: cleanup the code --- .github/workflows/ci.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e5b288..ff2d2a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,14 +36,19 @@ jobs: run: | poetry run uvicorn app:app --host 0.0.0.0 --port 8000 & - - name: Run tests and Publish Test Report + - name: Run tests working-directory: ./src env: BACKEND_CORS_ORIGINS: '["*"]' run: | sleep 5 # Wait a bit for the server to be fully up and running - poetry run pytest ./test/ --junitxml=./logs/pytest_report.xml || true - echo "Publishing Test Report" - curl -sSL https://github.com/dorny/test-reporter/releases/latest/download/test-reporter-linux -o test-reporter - chmod +x test-reporter - ./test-reporter -n 'Test Report' -p './logs/pytest_report.xml' -r 'java-junit' || true + poetry run pytest ./test/ --junitxml=./logs/pytest_report.xml + + - name: Publish Test Report + uses: dorny/test-reporter@v1 + if: failure() + with: + name: 'Test Report' + path: './src/logs/pytest_report.xml' + reporter: 'java-junit' + fail-on-error: false \ No newline at end of file From eb23bc59f4092e89870502448f1320c339bb4cd5 Mon Sep 17 00:00:00 2001 From: Kai NABETA Date: Wed, 25 Sep 2024 23:20:03 +0900 Subject: [PATCH 21/21] test: restore normal code --- src/test/unit/test_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/unit/test_example.py b/src/test/unit/test_example.py index 8c5ff16..41dc27a 100644 --- a/src/test/unit/test_example.py +++ b/src/test/unit/test_example.py @@ -9,5 +9,5 @@ def test_root_endpoint(): response = client.get("/") - assert response.status_code == 500 + assert response.status_code == 200 assert response.json() == expected_response