From b444ade6a4fad6210fb69f5547e1bf861a82b179 Mon Sep 17 00:00:00 2001 From: kingbuzzman Date: Sun, 8 Jun 2025 12:46:38 -0400 Subject: [PATCH 01/11] Adds coverage --- .coveragerc | 12 +++++++ .github/workflows/test.yml | 64 ++++++++++++++++++++++++++++++++++++-- setup.py | 1 + 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..e6a49c73 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,12 @@ +[run] +source = . +relative_files = true +omit = + setup.py + +[report] +skip_covered = false +show_missing = true + +[html] +show_contexts = true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2abc4e05..3a48bcf2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,7 +48,7 @@ jobs: docker run --rm -v ${{ github.workspace }}:/app -w /app python:${{ matrix.python-version }} bash -c " python -m pip install --upgrade pip setuptools wheel tox python -m pip install '.[test]' - pytest + pytest --cov-branch --cov-context=test --cov=. " - name: Run tests @@ -56,4 +56,64 @@ jobs: run: | python -m pip install --upgrade pip setuptools wheel tox python -m pip install '.[test]' - pytest + pytest --cov-branch --cov-context=test --cov=. + + - name: Set artifact name + shell: bash + run: | + ARTIFACT_NAME="coverage-${{ runner.os }}-py-${{ matrix.python-version }}" + ARTIFACT_NAME="${ARTIFACT_NAME//./}" + echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> "$GITHUB_ENV" + + - name: Upload coverage artifact + uses: actions/upload-artifact@v4 + with: + include-hidden-files: true + if-no-files-found: error + name: ${{ env.ARTIFACT_NAME }} + path: .coverage + retention-days: 1 + + coverage: + runs-on: ubuntu-latest + needs: test + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-python@v5 + with: + python-version: 3.13 + + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + path: downloaded_artifacts + + - name: Clean up temporary artifacts + uses: geekyeggo/delete-artifact@v5 + with: + name: coverage-* + + - name: Install dependencies + run: pip install coverage + + - name: Combine coverage.py + run: | + coverage combine $(find downloaded_artifacts/ -type f | xargs) + coverage xml + coverage html + coverage report --format=markdown >> $GITHUB_STEP_SUMMARY + cp coverage.xml htmlcov/coverage.xml + cp .coverage htmlcov/.coverage + + - name: Upload single coverage artifact + uses: actions/upload-artifact@v4 + with: + include-hidden-files: true + if-no-files-found: error + name: htmlcov + path: htmlcov + # Retention days for main branch is 90 days, for other branches is 1 day + retention-days: ${{ github.ref == 'refs/heads/master' && 90 || 1 }} diff --git a/setup.py b/setup.py index 9a28e31f..3526ca51 100644 --- a/setup.py +++ b/setup.py @@ -84,6 +84,7 @@ def launch_http_server(directory): "mock", "PyYAML", "pytest", + "pytest-cov", ] From f42d6e3722d4b00a46c803dcae3ef58fdd5daf6c Mon Sep 17 00:00:00 2001 From: Javier Buzzi Date: Sun, 15 Jun 2025 04:40:36 -0400 Subject: [PATCH 02/11] Update test.yml --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0a0beb0c..486ee59b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -119,7 +119,7 @@ jobs: retention-days: ${{ github.ref == 'refs/heads/master' && 90 || 1 }} release: - needs: [ test ] + needs: coverage name: PyPI runs-on: ubuntu-latest environment: pypi From 8b442717287505156a9d21778f020139a0837213 Mon Sep 17 00:00:00 2001 From: kingbuzzman Date: Sun, 15 Jun 2025 04:58:54 -0400 Subject: [PATCH 03/11] Messing with contexts --- tests/conftest.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..d133af63 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,17 @@ +import platform +import pytest +import sys + + +@pytest.fixture(autouse=True) +def cov(cov): + """ + Tags each test with the current OS + Python version. + This allows to see the coverage in greater detail. + """ + if not cov: + return + + context = "{}-py{}.{}".format(platform.system(), sys.version_info.major, sys.version_info.minor) + cov.switch_context(context) + return cov \ No newline at end of file From 4b08dcd3adf731ad4c065b72580e1444a72d07f4 Mon Sep 17 00:00:00 2001 From: kingbuzzman Date: Sun, 15 Jun 2025 05:11:16 -0400 Subject: [PATCH 04/11] Fingers crossed --- tests/conftest.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index d133af63..23a42651 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,7 +4,7 @@ @pytest.fixture(autouse=True) -def cov(cov): +def cov(cov, request): """ Tags each test with the current OS + Python version. This allows to see the coverage in greater detail. @@ -12,6 +12,8 @@ def cov(cov): if not cov: return - context = "{}-py{}.{}".format(platform.system(), sys.version_info.major, sys.version_info.minor) + sys_context = "{}-py{}.{}".format(platform.system(), sys.version_info.major, sys.version_info.minor) + test_name = request.node.nodeid + context = "[{}]{}".format(sys_context, test_name) cov.switch_context(context) return cov \ No newline at end of file From bef87aff73a88f40af79894ea0c36be92d5995e6 Mon Sep 17 00:00:00 2001 From: kingbuzzman Date: Sun, 15 Jun 2025 05:16:20 -0400 Subject: [PATCH 05/11] Getting coverage detail.. --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 23a42651..3ee0f3f0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,6 +14,6 @@ def cov(cov, request): sys_context = "{}-py{}.{}".format(platform.system(), sys.version_info.major, sys.version_info.minor) test_name = request.node.nodeid - context = "[{}]{}".format(sys_context, test_name) + context = "{}_{}".format(sys_context, test_name) cov.switch_context(context) return cov \ No newline at end of file From 1cd977a5395da740a97fe1d31b988cfb63563e0a Mon Sep 17 00:00:00 2001 From: kingbuzzman Date: Sun, 15 Jun 2025 06:28:49 -0400 Subject: [PATCH 06/11] . --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 486ee59b..1d5bc459 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -105,6 +105,7 @@ jobs: coverage xml coverage html coverage report --format=markdown >> $GITHUB_STEP_SUMMARY + cp downloaded_artifacts htmlcov/all_coverage cp coverage.xml htmlcov/coverage.xml cp .coverage htmlcov/.coverage From 4171d9a06e68f2ff286eb3788d7152660f70edac Mon Sep 17 00:00:00 2001 From: kingbuzzman Date: Sun, 15 Jun 2025 06:28:49 -0400 Subject: [PATCH 07/11] . --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 486ee59b..56eb34cf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -105,8 +105,9 @@ jobs: coverage xml coverage html coverage report --format=markdown >> $GITHUB_STEP_SUMMARY + cp downloaded_artifacts htmlcov/all_coverage cp coverage.xml htmlcov/coverage.xml - cp .coverage htmlcov/.coverage + cp -r .coverage htmlcov/.coverage - name: Upload single coverage artifact uses: actions/upload-artifact@v4 From 207e0dcd686eda2dc1f9f55e30b4fdf6b7ba3441 Mon Sep 17 00:00:00 2001 From: kingbuzzman Date: Sun, 15 Jun 2025 14:01:23 -0400 Subject: [PATCH 08/11] . --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fb4b7f5c..14915aff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -99,11 +99,12 @@ jobs: - name: Combine coverage.py run: | + cp -r downloaded_artifacts all_coverage coverage combine $(find downloaded_artifacts/ -type f | xargs) coverage xml coverage html coverage report --format=markdown >> $GITHUB_STEP_SUMMARY - cp -r downloaded_artifacts htmlcov/all_coverage + cp -r all_coverage htmlcov/all_coverage cp coverage.xml htmlcov/coverage.xml cp .coverage htmlcov/.coverage From 2c2e3bf376b5f3e1f745aca90be868ecf269dd2d Mon Sep 17 00:00:00 2001 From: Javier Buzzi Date: Mon, 16 Jun 2025 04:51:56 -0400 Subject: [PATCH 09/11] Update test.yml --- .github/workflows/test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 14915aff..f51ce6e7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -89,11 +89,6 @@ jobs: with: path: downloaded_artifacts - - name: Clean up temporary artifacts - uses: geekyeggo/delete-artifact@f275313e70c08f6120db482d7a6b98377786765b # v5.1.0 - with: - name: coverage-* - - name: Install dependencies run: pip install coverage @@ -118,6 +113,11 @@ jobs: # Retention days for main branch is 90 days, for other branches is 1 day retention-days: ${{ github.ref == 'refs/heads/master' && 90 || 1 }} + - name: Clean up temporary artifacts + uses: geekyeggo/delete-artifact@f275313e70c08f6120db482d7a6b98377786765b # v5.1.0 + with: + name: coverage-* + release: needs: [test, coverage] name: PyPI From a6af1506ae049a48aa2784d975c3041c7a7a82e2 Mon Sep 17 00:00:00 2001 From: Javier Buzzi Date: Mon, 16 Jun 2025 05:27:20 -0400 Subject: [PATCH 10/11] Update conftest.py --- tests/conftest.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 3ee0f3f0..f0989bae 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,6 +14,7 @@ def cov(cov, request): sys_context = "{}-py{}.{}".format(platform.system(), sys.version_info.major, sys.version_info.minor) test_name = request.node.nodeid - context = "{}_{}".format(sys_context, test_name) + context = "{}_{}".format(test_name, sys_context) cov.switch_context(context) - return cov \ No newline at end of file + return cov + From 424fd2d647e2ec4b62fda83cac9de25ac9f7218d Mon Sep 17 00:00:00 2001 From: kingbuzzman Date: Sun, 6 Jul 2025 11:55:17 -0400 Subject: [PATCH 11/11] Does it work? --- tests/conftest.py | 5 ++--- tests/test_configargparse.py | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index f0989bae..8c3c7e8a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,9 +12,8 @@ def cov(cov, request): if not cov: return - sys_context = "{}-py{}.{}".format(platform.system(), sys.version_info.major, sys.version_info.minor) + sys_context = f"{platform.system()}-py{sys.version_info.major}.{ sys.version_info.minor}".lower() test_name = request.node.nodeid - context = "{}_{}".format(test_name, sys_context) + context = f"{test_name}_{sys_context}" cov.switch_context(context) return cov - diff --git a/tests/test_configargparse.py b/tests/test_configargparse.py index 968b2b02..4f1c8e23 100644 --- a/tests/test_configargparse.py +++ b/tests/test_configargparse.py @@ -60,7 +60,6 @@ def captured_output(): class TestCase(unittest.TestCase): - def initParser(self, *args, **kwargs): p = configargparse.ArgParser(*args, **kwargs) self.parser = replace_error_method(p)