|
4 | 4 | Increase test coverage
|
5 | 5 | ======================
|
6 | 6 |
|
| 7 | +.. raw:: html |
| 8 | + |
| 9 | + <script> |
| 10 | + document.addEventListener('DOMContentLoaded', function() { |
| 11 | + activateTab(getOS()); |
| 12 | + }); |
| 13 | + </script> |
| 14 | + |
7 | 15 | Python development follows a practice that all semantic changes and additions
|
8 | 16 | to the language and :abbr:`stdlib (standard library)` are accompanied by
|
9 | 17 | appropriate unit tests. Unfortunately Python was in existence for a long time
|
@@ -87,23 +95,35 @@ just built, and this built version of Python will not see packages installed
|
87 | 95 | into your default version of Python. One option is to use a virtual environment
|
88 | 96 | to install coverage.
|
89 | 97 |
|
90 |
| -On Unix run:: |
| 98 | +.. tab:: Unix |
| 99 | + |
| 100 | + Run: |
| 101 | + |
| 102 | + .. code-block:: shell |
| 103 | +
|
| 104 | + ./python -m venv ../cpython-venv |
| 105 | + source ../cpython-venv/bin/activate |
| 106 | + pip install coverage |
| 107 | +
|
| 108 | +.. tab:: macOS |
91 | 109 |
|
92 |
| - ./python -m venv ../cpython-venv |
93 |
| - source ../cpython-venv/bin/activate |
94 |
| - pip install coverage |
| 110 | + On :ref:`most <mac-python.exe>` macOS systems run: |
95 | 111 |
|
96 |
| -On :ref:`most <mac-python.exe>` macOS systems run:: |
| 112 | + .. code-block:: shell |
97 | 113 |
|
98 |
| - ./python.exe -m venv ../cpython-venv |
99 |
| - source ../cpython-venv/bin/activate |
100 |
| - pip install coverage |
| 114 | + ./python.exe -m venv ../cpython-venv |
| 115 | + source ../cpython-venv/bin/activate |
| 116 | + pip install coverage |
101 | 117 |
|
102 |
| -On Windows run:: |
| 118 | +.. tab:: Windows |
103 | 119 |
|
104 |
| - python.bat -m venv ..\\cpython-venv |
105 |
| - ..\\cpython-venv\\Scripts\\activate.bat |
106 |
| - pip install coverage |
| 120 | + Run: |
| 121 | + |
| 122 | + .. code-block:: dosbatch |
| 123 | +
|
| 124 | + python.bat -m venv ..\\cpython-venv |
| 125 | + ..\\cpython-venv\\Scripts\\activate.bat |
| 126 | + pip install coverage |
107 | 127 |
|
108 | 128 | You can now use python without the ./ for the rest of these instructions, as
|
109 | 129 | long as your venv is activated. For more info on venv see `Virtual Environment
|
@@ -231,19 +251,49 @@ Measuring coverage of C code with gcov and lcov
|
231 | 251 |
|
232 | 252 | It's also possible to measure the function, line and branch coverage of
|
233 | 253 | Python's C code. Right now only GCC with `gcov`_ is supported. In order to
|
234 |
| -create an instrumented build of Python with gcov, run:: |
| 254 | +create an instrumented build of Python with gcov, run: |
| 255 | + |
| 256 | +.. tab:: Unix/macOS |
| 257 | + |
| 258 | + .. code-block:: shell |
| 259 | +
|
| 260 | + make coverage |
| 261 | +
|
| 262 | +.. tab:: Windows |
235 | 263 |
|
236 |
| - make coverage |
| 264 | + .. code-block:: dosbatch |
| 265 | +
|
| 266 | + .\make coverage |
237 | 267 |
|
238 | 268 | Then run some code and gather coverage data with the ``gcov`` command. In
|
239 |
| -order to create a HTML report you can install `lcov`_. The command:: |
| 269 | +order to create a HTML report you can install `lcov`_. The command: |
| 270 | + |
| 271 | +.. tab:: Unix/macOS |
| 272 | + |
| 273 | + .. code-block:: shell |
| 274 | +
|
| 275 | + make coverage-lcov |
| 276 | +
|
| 277 | +.. tab:: Windows |
| 278 | + |
| 279 | + .. code-block:: dosbatch |
240 | 280 |
|
241 |
| - make coverage-lcov |
| 281 | + .\make coverage-lcov |
242 | 282 |
|
243 | 283 | assembles coverage data, removes 3rd party and system libraries and finally
|
244 |
| -creates a report. You can skip both steps and just run:: |
| 284 | +creates a report. You can skip both steps and just run: |
| 285 | + |
| 286 | +.. tab:: Unix/macOS |
| 287 | + |
| 288 | + .. code-block:: shell |
| 289 | +
|
| 290 | + make coverage-report |
| 291 | +
|
| 292 | +.. tab:: Windows |
| 293 | + |
| 294 | + .. code-block:: dosbatch |
245 | 295 |
|
246 |
| - make coverage-report |
| 296 | + .\make coverage-report |
247 | 297 |
|
248 | 298 | if you like to generate a coverage report for Python's stdlib tests. It takes
|
249 | 299 | about 20 to 30 minutes on a modern computer.
|
|
0 commit comments