File tree Expand file tree Collapse file tree 4 files changed +82
-0
lines changed Expand file tree Collapse file tree 4 files changed +82
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : Python package
2
+
3
+ on :
4
+ - push
5
+ - pull_request
6
+
7
+ jobs :
8
+ build :
9
+ runs-on : ubuntu-latest
10
+ strategy :
11
+ matrix :
12
+ python-version : ['3.10', '3.11', '3.12.0']
13
+
14
+ steps :
15
+ - uses : actions/checkout@v3
16
+ - name : Set up Python ${{ matrix.python-version }}
17
+ uses : actions/setup-python@v4
18
+ with :
19
+ python-version : ${{ matrix.python-version }}
20
+ - name : Install dependencies
21
+ run : |
22
+ python -m pip install --upgrade pip
23
+ python -m pip install tox tox-gh-actions
24
+ - name : Test with tox
25
+ run : tox
Original file line number Diff line number Diff line change
1
+ .coverage
Original file line number Diff line number Diff line change
1
+ import asyncio
2
+ import coverage
3
+
4
+
5
+ async def run ():
6
+ def raise_exception ():
7
+ raise RuntimeError ("This is a test exception." )
8
+
9
+ async def return_false ():
10
+ # simply returning false here causes the incorrectly missed line to be marked as hit
11
+ try :
12
+ await asyncio .to_thread (raise_exception )
13
+ # raise RuntimeError("This is a test exception.") # doing this instead will cause line below to show up
14
+ finally :
15
+ return False
16
+
17
+ # remove this conditional also fixes the problem
18
+ if await return_false ():
19
+ return False
20
+
21
+ await asyncio .to_thread (print , "hello" ,) # this line is incorrectly marked as missing the coverage report
22
+
23
+
24
+ if __name__ == '__main__' :
25
+ cov = coverage .Coverage (branch = False )
26
+ cov .start ()
27
+
28
+ asyncio .run (run ())
29
+
30
+ cov .stop ()
31
+ cov .save ()
32
+
33
+ cov .report (show_missing = True )
Original file line number Diff line number Diff line change
1
+ [tox]
2
+ requires =
3
+ tox>=4
4
+ tox-gh-actions
5
+
6
+ env_list = py{310,311,312_0}
7
+
8
+ [gh-actions]
9
+ python =
10
+ 3.10: py310
11
+ 3.11: py312
12
+ 3.12.0: py312_0
13
+
14
+ [testenv:py312_0]
15
+ basepython = python3.12.0
16
+
17
+ [testenv]
18
+ description = run unit tests
19
+ deps =
20
+ coverage
21
+ commands =
22
+ python --version
23
+ python example.py
You can’t perform that action at this time.
0 commit comments