Skip to content

Commit 3645b1a

Browse files
authored
Merge pull request #1337 from dbfixtures/coverage-combine
Improve reliability of Coverage reporting on CI
2 parents d912c6a + 872f852 commit 3645b1a

9 files changed

Lines changed: 77 additions & 10 deletions

File tree

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[run]
2+
concurrency = multiprocessing
3+
parallel = true
24
include =
35
*/pytest_postgresql/*
46
*/tests/*

.github/workflows/dockerised-postgres.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,23 @@ jobs:
5555
python-version: ${{ matrix.python-version }}
5656
allow-prereleases: true
5757
- name: Run test noproc fixture on docker
58+
id: run_docker_tests
5859
uses: fizyk/actions-reuse/.github/actions/pipenv-run@v4.4.7
5960
with:
60-
command: pytest -n 0 --max-worker-restart 0 -k docker --postgresql-host=localhost --postgresql-port 5433 --postgresql-password=postgres --cov-report=xml:coverage-docker.xml
61+
command: python -m coverage run --data-file=.coverage.docker -m pytest -n 0 --max-worker-restart 0 -k docker --postgresql-host=localhost --postgresql-port 5433 --postgresql-password=postgres
62+
env: '{"COVERAGE_PROCESS_START": ".coveragerc", "COVERAGE_FILE": ".coverage.docker"}'
63+
- name: Combine and export docker coverage
64+
if: ${{ always() && (steps.run_docker_tests.conclusion == 'success' || steps.run_docker_tests.conclusion == 'failure') }}
65+
uses: fizyk/actions-reuse/.github/actions/coverage-combine-export@v4.4.7
66+
with:
67+
data-file: .coverage.docker
68+
output-file: coverage-docker.xml
6169
- name: Upload coverage to Codecov
70+
if: always()
6271
uses: codecov/codecov-action@v6.0.0
6372
with:
6473
token: ${{ secrets.codecov_token }}
6574
flags: unittests
6675
env_vars: OS,PYTHON
6776
fail_ci_if_error: false
77+
files: coverage-docker.xml

.github/workflows/oldest-postgres.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,40 @@ jobs:
5959
with:
6060
command: pip install -r oldest/requirements.txt
6161
- name: Run tests without xdist
62+
id: run_serial_tests
6263
uses: fizyk/actions-reuse/.github/actions/pipenv-run@v4.4.7
6364
with:
64-
command: pytest -c pyproject.oldest.toml -svv -p no:xdist --postgresql-exec="/usr/lib/postgresql/${{ inputs.postgresql }}/bin/pg_ctl" -k "not docker" --cov-report=xml
65+
command: python -m coverage run --data-file=.coverage.serial -m pytest -c pyproject.oldest.toml -svv -p no:xdist --postgresql-exec="/usr/lib/postgresql/${{ inputs.postgresql }}/bin/pg_ctl" -k "not docker"
66+
env: '{"COVERAGE_PROCESS_START": ".coveragerc", "COVERAGE_FILE": ".coverage.serial"}'
67+
- name: Combine and export serial coverage
68+
if: ${{ always() && (steps.run_serial_tests.conclusion == 'success' || steps.run_serial_tests.conclusion == 'failure') }}
69+
uses: fizyk/actions-reuse/.github/actions/coverage-combine-export@v4.4.7
70+
with:
71+
data-file: .coverage.serial
72+
output-file: coverage-serial.xml
6573
- name: Run xdist test
74+
id: run_xdist_tests
6675
uses: fizyk/actions-reuse/.github/actions/pipenv-run@v4.4.7
6776
with:
68-
command: pytest -n auto -c pyproject.oldest.toml --dist loadgroup --max-worker-restart 0 --postgresql-exec="/usr/lib/postgresql/${{ inputs.postgresql }}/bin/pg_ctl" -k "not docker" --cov-report=xml:coverage-xdist.xml
77+
command: python -m coverage run --data-file=.coverage.xdist -m pytest -n auto -c pyproject.oldest.toml --dist loadgroup --max-worker-restart 0 --postgresql-exec="/usr/lib/postgresql/${{ inputs.postgresql }}/bin/pg_ctl" -k "not docker"
78+
env: '{"COVERAGE_PROCESS_START": ".coveragerc", "COVERAGE_FILE": ".coverage.xdist"}'
79+
- name: Combine and export xdist coverage
80+
if: ${{ always() && (steps.run_xdist_tests.conclusion == 'success' || steps.run_xdist_tests.conclusion == 'failure') }}
81+
uses: fizyk/actions-reuse/.github/actions/coverage-combine-export@v4.4.7
82+
with:
83+
data-file: .coverage.xdist
84+
output-file: coverage-xdist.xml
6985
- uses: actions/upload-artifact@v7
7086
if: failure()
7187
with:
7288
name: postgresql-${{ matrix.python-version }}-${{ inputs.postgresql }}
7389
path: /tmp/pytest-of-runner/**
7490
- name: Upload coverage to Codecov
91+
if: always()
7592
uses: codecov/codecov-action@v6.0.0
7693
with:
7794
token: ${{ secrets.codecov_token }}
7895
flags: unittests
7996
env_vars: OS,PYTHON
8097
fail_ci_if_error: false
98+
files: coverage-serial.xml,coverage-xdist.xml

.github/workflows/single-postgres-windows.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,40 @@ jobs:
5757
exit 1
5858
}
5959
- name: Run test
60+
id: run_serial_tests
6061
uses: fizyk/actions-reuse/.github/actions/pipenv-run@v4.4.4
6162
with:
62-
command: pytest -svv -p no:xdist --postgresql-exec="${{ env.POSTGRESQL_EXEC }}" -k "not docker" --cov-report=xml --basetemp="${{ runner.temp }}/pytest-basetemp"
63+
command: python -m coverage run --data-file=.coverage.serial -m pytest -svv -p no:xdist --postgresql-exec="${{ env.POSTGRESQL_EXEC }}" -k "not docker" --basetemp="${{ runner.temp }}/pytest-basetemp"
64+
env: '{"COVERAGE_PROCESS_START": ".coveragerc", "COVERAGE_FILE": ".coverage.serial"}'
65+
- name: Combine and export serial coverage
66+
if: ${{ always() && (steps.run_serial_tests.conclusion == 'success' || steps.run_serial_tests.conclusion == 'failure') }}
67+
uses: fizyk/actions-reuse/.github/actions/coverage-combine-export@v4.4.4
68+
with:
69+
data-file: .coverage.serial
70+
output-file: coverage-serial.xml
6371
- name: Run xdist test
72+
id: run_xdist_tests
6473
uses: fizyk/actions-reuse/.github/actions/pipenv-run@v4.4.4
6574
with:
66-
command: pytest -n auto --dist loadgroup --max-worker-restart 0 --postgresql-exec="${{ env.POSTGRESQL_EXEC }}" -k "not docker" --cov-report=xml:coverage-xdist.xml --basetemp="${{ runner.temp }}/pytest-basetemp"
75+
command: python -m coverage run --data-file=.coverage.xdist -m pytest -n auto --dist loadgroup --max-worker-restart 0 --postgresql-exec="${{ env.POSTGRESQL_EXEC }}" -k "not docker" --basetemp="${{ runner.temp }}/pytest-basetemp"
76+
env: '{"COVERAGE_PROCESS_START": ".coveragerc", "COVERAGE_FILE": ".coverage.xdist"}'
77+
- name: Combine and export xdist coverage
78+
if: ${{ always() && (steps.run_xdist_tests.conclusion == 'success' || steps.run_xdist_tests.conclusion == 'failure') }}
79+
uses: fizyk/actions-reuse/.github/actions/coverage-combine-export@v4.4.4
80+
with:
81+
data-file: .coverage.xdist
82+
output-file: coverage-xdist.xml
6783
- uses: actions/upload-artifact@v7
6884
if: failure()
6985
with:
7086
name: postgresql-windows-${{ matrix.python-version }}-${{ inputs.postgresql }}
7187
path: ${{ runner.temp }}/pytest-basetemp/**
7288
- name: Upload coverage to Codecov
89+
if: always()
7390
uses: codecov/codecov-action@v6.0.0
7491
with:
7592
token: ${{ secrets.codecov_token }}
7693
flags: unittests
7794
env_vars: OS,PYTHON
7895
fail_ci_if_error: false
96+
files: coverage-serial.xml,coverage-xdist.xml

.github/workflows/single-postgres.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,40 @@ jobs:
7373
if: ${{ contains(matrix.python-version, 'pypy') && runner.os == 'Linux' }}
7474
run: sudo apt install libpq5
7575
- name: Run test
76+
id: run_serial_tests
7677
uses: fizyk/actions-reuse/.github/actions/pipenv-run@v4.4.7
7778
with:
78-
command: pytest -svv -p no:xdist --postgresql-exec="${{ env.POSTGRESQL_EXEC }}" -k "not docker" --cov-report=xml --basetemp="${{ runner.temp }}/pytest-basetemp"
79+
command: python -m coverage run --data-file=.coverage.serial -m pytest -svv -p no:xdist --postgresql-exec="${{ env.POSTGRESQL_EXEC }}" -k "not docker" --basetemp="${{ runner.temp }}/pytest-basetemp"
80+
env: '{"COVERAGE_PROCESS_START": ".coveragerc", "COVERAGE_FILE": ".coverage.serial"}'
81+
- name: Combine and export serial coverage
82+
if: ${{ always() && (steps.run_serial_tests.conclusion == 'success' || steps.run_serial_tests.conclusion == 'failure') }}
83+
uses: fizyk/actions-reuse/.github/actions/coverage-combine-export@v4.4.7
84+
with:
85+
data-file: .coverage.serial
86+
output-file: coverage-serial.xml
7987
- name: Run xdist test
88+
id: run_xdist_tests
8089
uses: fizyk/actions-reuse/.github/actions/pipenv-run@v4.4.7
8190
with:
82-
command: pytest -n auto --dist loadgroup --max-worker-restart 0 --postgresql-exec="${{ env.POSTGRESQL_EXEC }}" -k "not docker" --cov-report=xml:coverage-xdist.xml --basetemp="${{ runner.temp }}/pytest-basetemp"
91+
command: python -m coverage run --data-file=.coverage.xdist -m pytest -n auto --dist loadgroup --max-worker-restart 0 --postgresql-exec="${{ env.POSTGRESQL_EXEC }}" -k "not docker" --basetemp="${{ runner.temp }}/pytest-basetemp"
92+
env: '{"COVERAGE_PROCESS_START": ".coveragerc", "COVERAGE_FILE": ".coverage.xdist"}'
93+
- name: Combine and export xdist coverage
94+
if: ${{ always() && (steps.run_xdist_tests.conclusion == 'success' || steps.run_xdist_tests.conclusion == 'failure') }}
95+
uses: fizyk/actions-reuse/.github/actions/coverage-combine-export@v4.4.7
96+
with:
97+
data-file: .coverage.xdist
98+
output-file: coverage-xdist.xml
8399
- uses: actions/upload-artifact@v7
84100
if: failure()
85101
with:
86102
name: postgresql-${{ matrix.python-version }}-${{ inputs.postgresql }}
87103
path: ${{ runner.temp }}/pytest-basetemp/**
88104
- name: Upload coverage to Codecov
105+
if: always()
89106
uses: codecov/codecov-action@v6.0.0
90107
with:
91108
token: ${{ secrets.codecov_token }}
92109
flags: unittests
93110
env_vars: OS,PYTHON
94111
fail_ci_if_error: false
112+
files: coverage-serial.xml,coverage-xdist.xml

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pytest-postgresql = {path = ".", editable = true}
1414
[dev-packages]
1515
towncrier = "==25.8.0"
1616
psycopg-binary = {version = "==3.3.4", markers="implementation_name == 'cpython'"}
17-
pytest-cov = "==7.1.0"
17+
coverage = ">=7.0"
1818
pytest-xdist = "==3.8.0"
1919
mock = "==5.2.0"
2020
mypy = {version = "==2.1.0", markers="implementation_name == 'cpython'"}

newsfragments/+4ed991c2.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve reliability of Coverage reporting on CI

pyproject.oldest.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.pytest.ini_options]
22
xfail_strict=true
3-
addopts = "--showlocals --verbose --cov"
3+
addopts = "--showlocals --verbose"
44
testpaths = "tests"
55
pytester_example_dir = "tests/examples"
66
norecursedirs = "examples"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespaces = false
5858

5959
[tool.pytest]
6060
strict_xfail=true
61-
addopts = ["--showlocals", "--verbose", "--cov"]
61+
addopts = ["--showlocals", "--verbose"]
6262
testpaths = ["tests"]
6363
pytester_example_dir = "tests/examples"
6464
norecursedirs = ["examples"]

0 commit comments

Comments
 (0)