bpo-30934: Document coverage details for idlelib tests (#2711) · python/cpython@95bebb7 (original) (raw)
`@@ -159,3 +159,59 @@ complete, though some tests need improvement. To run all htests, run the
`
159
159
`htest file from an editor or from the command line with:
`
160
160
``
161
161
`python -m idlelib.idle_test.htest
`
``
162
+
``
163
+
``
164
`+
- Test Coverage
`
``
165
+
``
166
`+
Install the coverage package into your Python 3.6 site-packages
`
``
167
`+
directory. (Its exact location depends on the OS).
`
``
168
`+
python3 -m pip install coverage
`
``
169
`+
(On Windows, replace 'python3 with 'py -3.6' or perhaps just 'python'.)
`
``
170
+
``
171
`+
The problem with running coverage with repository python is that
`
``
172
`+
coverage uses absolute imports for its submodules, hence it needs to be
`
``
173
`+
in a directory in sys.path. One solution: copy the package to the
`
``
174
`+
directory containing the cpython repository. Call it 'dev'. Then run
`
``
175
`+
coverage either directly or from a script in that directory so that
`
``
176
`+
'dev' is prepended to sys.path.
`
``
177
+
``
178
`+
Either edit or add dev/.coveragerc so it looks something like this.
`
``
179
`+
`
``
180
`+
.coveragerc sets coverage options.
`
``
181
`+
[run]
`
``
182
`+
branch = True
`
``
183
+
``
184
`+
[report]
`
``
185
`+
Regexes for lines to exclude from consideration
`
``
186
`+
exclude_lines =
`
``
187
`+
Don't complain if non-runnable code isn't run:
`
``
188
`+
if 0:
`
``
189
`+
if name == .main.:
`
``
190
+
``
191
`+
.*# htest #
`
``
192
`+
if not _utest:
`
``
193
`+
if _htest:
`
``
194
`+
`
``
195
`+
The additions for IDLE are 'branch = True', to test coverage both ways,
`
``
196
`+
and the last three exclude lines, to exclude things peculiar to IDLE
`
``
197
`+
that are not executed during tests.
`
``
198
+
``
199
`+
A script like the following cover.bat (for Windows) is very handy.
`
``
200
`+
`
``
201
`+
@echo off
`
``
202
`+
rem Usage: cover filename [test_ suffix] # proper case required by coverage
`
``
203
`+
rem filename without .py, 2nd parameter if test is not test_filename
`
``
204
`+
setlocal
`
``
205
`+
set py=f:\dev\3x\pcbuild\win32\python_d.exe
`
``
206
`+
set src=idlelib.%1
`
``
207
`+
if "%2" EQU "" set tst=f:/dev/3x/Lib/idlelib/idle_test/test_%1.py
`
``
208
`+
if "%2" NEQ "" set tst=f:/dev/ex/Lib/idlelib/idle_test/test_%2.py
`
``
209
+
``
210
`+
%py% -m coverage run --pylib --source=%src% %tst%
`
``
211
`+
%py% -m coverage report --show-missing
`
``
212
`+
%py% -m coverage html
`
``
213
`+
start htmlcov\3x_Lib_idlelib_%1_py.html
`
``
214
`+
rem Above opens new report; htmlcov\index.html displays report index
`
``
215
`+
`
``
216
`+
The second parameter was added for tests of module x not named test_x.
`
``
217
`+
(There were several before modules were renamed, now only one is left.)
`