Skip to content

Commit 7078342

Browse files
committed
Add coverage workflow
1 parent f66c1fb commit 7078342

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

.github/workflows/ci.yml

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,28 @@ jobs:
6464
python-version: ${{ matrix.python-version }}
6565
allow-prereleases: true
6666

67+
- name: Install coverage
68+
run: |
69+
# Be wary that this does not install typing_extensions in the future
70+
pip install coverage
71+
6772
- name: Test typing_extensions
6873
run: |
6974
# Be wary of running `pip install` here, since it becomes easy for us to
7075
# accidentally pick up typing_extensions as installed by a dependency
7176
cd src
7277
python --version # just to make sure we're running the right one
73-
python -m unittest test_typing_extensions.py
78+
export COVERAGE_FILE=.coverage_${{ matrix.python-version }}
79+
# Run with coverage omit files that are executed in tempfiles
80+
coverage run --omit ann_module*,inspect* -m unittest test_typing_extensions.py
81+
82+
- name: Archive code coverage results
83+
uses: actions/upload-artifact@v4
84+
with:
85+
name: .coverage_${{ matrix.python-version }}
86+
path: ./src/.coverage*
87+
include-hidden-files: true
88+
compression-level: 0 # no compression
7489

7590
- name: Test CPython typing test suite
7691
# Test suite fails on PyPy even without typing_extensions
@@ -80,7 +95,7 @@ jobs:
8095
# Run the typing test suite from CPython with typing_extensions installed,
8196
# because we monkeypatch typing under some circumstances.
8297
python -c 'import typing_extensions; import test.__main__' test_typing -v
83-
98+
8499
linting:
85100
name: Lint
86101

@@ -130,3 +145,36 @@ jobs:
130145
title: `Daily tests failed on ${new Date().toDateString()}`,
131146
body: "Runs listed here: https://github.com/python/typing_extensions/actions/workflows/ci.yml",
132147
})
148+
149+
report-coverage:
150+
name: Report coverage
151+
152+
runs-on: ubuntu-latest
153+
154+
needs: [tests]
155+
156+
if: ${{ always() }}
157+
158+
steps:
159+
- uses: actions/checkout@v4
160+
- name: Set up Python
161+
uses: actions/setup-python@v5
162+
with:
163+
python-version: "3"
164+
- name: Download coverage artifacts
165+
uses: actions/download-artifact@v4
166+
with:
167+
pattern: .coverage_*
168+
path: .
169+
# merge only when files are named differently
170+
merge-multiple: true
171+
- name: Install dependencies
172+
run: pip install coverage
173+
- name: Combine coverage results
174+
run: |
175+
# List the files to see what we have
176+
echo "Combining coverage files:"
177+
coverage combine --data-file=.coverage .coverage*
178+
# add -i to ignore parsed code of temp files.
179+
coverage report -i
180+
coverage xml -i

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ venv*/
1616
*.swp
1717
*.pyc
1818
*.egg-info/
19+
20+
.coverage*

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,5 @@ ignore = [
114114
[tool.ruff.lint.isort]
115115
extra-standard-library = ["tomllib"]
116116
known-first-party = ["typing_extensions", "_typed_dict_test_helper"]
117+
118+

src/test_typing_extensions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6886,6 +6886,13 @@ def test_typing_extensions_compiles_with_opt(self):
68866886
except subprocess.CalledProcessError:
68876887
self.fail('Module does not compile with optimize=2 (-OO flag).')
68886888

6889+
def test_typing_extensions_is_not_installed(self):
6890+
#import importlib
6891+
#with self.assertRaises(ModuleNotFoundError):
6892+
# importlib.import_module("typing_extensions")
6893+
# Importlib tests fail on GitHub CI
6894+
# weak alternative to check that no version in site-packages is used
6895+
self.assertIn("src/typing_extensions.py", typing_extensions.__file__)
68896896

68906897
class CoolEmployee(NamedTuple):
68916898
name: str

0 commit comments

Comments
 (0)