From 16cebb46dad989bd756cf6e1dfe52e297f146652 Mon Sep 17 00:00:00 2001 From: "Mr. Zipped" <81937711+MrPanda-to-you@users.noreply.github.com> Date: Wed, 14 Jun 2023 23:41:27 +0000 Subject: [PATCH 1/4] 1st phase --- .github/workflows/ci_cd_wf.yml | 29 +++++++++++++++++++++++++++++ tests/test_calculator.py | 17 +++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 .github/workflows/ci_cd_wf.yml diff --git a/.github/workflows/ci_cd_wf.yml b/.github/workflows/ci_cd_wf.yml new file mode 100644 index 00000000..8ca03d4c --- /dev/null +++ b/.github/workflows/ci_cd_wf.yml @@ -0,0 +1,29 @@ +name: test + +on: + push: + branches: + - main + pull_request: + branches: + - "*" + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Check out repo code + uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v3 + with: + python-version: "3.x" + + - name: Install Dependencies + run: | + python -m pip install -r requirements.txt + - name: Run tests + run: | + python -m pytest -v tests \ No newline at end of file diff --git a/tests/test_calculator.py b/tests/test_calculator.py index e69de29b..aeae4a4d 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -0,0 +1,17 @@ +from calculator import add, div, mul, sub + + +def test_add(): + assert add(1, 1) == 2 + + +def test_sub(): + assert sub(1, 1) == 0 + + +def test_mul(): + assert mul(1, 1) == 1 + + +def test_div(): + assert div(2, 1) == 2 \ No newline at end of file From 489be9f9f1decfa6c9e66c5eb2786070f76aa853 Mon Sep 17 00:00:00 2001 From: "Mr. Zipped" <81937711+MrPanda-to-you@users.noreply.github.com> Date: Wed, 14 Jun 2023 23:42:28 +0000 Subject: [PATCH 2/4] Added to ht enew branch intender error --- tests/test_calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_calculator.py b/tests/test_calculator.py index aeae4a4d..3763f12c 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -2,7 +2,7 @@ def test_add(): - assert add(1, 1) == 2 + assert add(1,1) == 0 def test_sub(): From 1da1b52199fa9ea15c0347d8a777537c681ebe2b Mon Sep 17 00:00:00 2001 From: "Mr. Zipped" <81937711+MrPanda-to-you@users.noreply.github.com> Date: Wed, 14 Jun 2023 23:44:37 +0000 Subject: [PATCH 3/4] Ammended error --- tests/test_calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 3763f12c..aeae4a4d 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -2,7 +2,7 @@ def test_add(): - assert add(1,1) == 0 + assert add(1, 1) == 2 def test_sub(): From 378588ef4256c0212a58db4effa885c4a88fb6a9 Mon Sep 17 00:00:00 2001 From: "Mr. Zipped" <81937711+MrPanda-to-you@users.noreply.github.com> Date: Thu, 15 Jun 2023 00:00:25 +0000 Subject: [PATCH 4/4] Add Test Coverage Reports as Comments in Pull Req --- .github/workflows/pytest_coverage_comment.yml | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/pytest_coverage_comment.yml diff --git a/.github/workflows/pytest_coverage_comment.yml b/.github/workflows/pytest_coverage_comment.yml new file mode 100644 index 00000000..812a2015 --- /dev/null +++ b/.github/workflows/pytest_coverage_comment.yml @@ -0,0 +1,27 @@ +name: pytest-coverage-comment +on: + pull_request: + branches: + - '*' +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest pytest-cov + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Build coverage file + run: | + pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=week1-devops week1-devops/tests/ | tee pytest-coverage.txt + - name: Pytest coverage comment + uses: MishaKav/pytest-coverage-comment@main + with: + pytest-coverage-path: ./pytest-coverage.txt + junitxml-path: ./pytest.xml