Skip to content

Commit

Permalink
Add inline tabs on Increase Test Coverage page for commands on differ…
Browse files Browse the repository at this point in the history
…ent systems (#1228)
  • Loading branch information
lancegoyke authored Nov 23, 2023
1 parent 6d96e57 commit 40d6473
Showing 1 changed file with 68 additions and 18 deletions.
86 changes: 68 additions & 18 deletions testing/coverage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
Increase test coverage
======================

.. raw:: html

<script>
document.addEventListener('DOMContentLoaded', function() {
activateTab(getOS());
});
</script>

Python development follows a practice that all semantic changes and additions
to the language and :abbr:`stdlib (standard library)` are accompanied by
appropriate unit tests. Unfortunately Python was in existence for a long time
Expand Down Expand Up @@ -87,23 +95,35 @@ just built, and this built version of Python will not see packages installed
into your default version of Python. One option is to use a virtual environment
to install coverage.

On Unix run::
.. tab:: Unix

Run:

.. code-block:: shell
./python -m venv ../cpython-venv
source ../cpython-venv/bin/activate
pip install coverage
.. tab:: macOS

./python -m venv ../cpython-venv
source ../cpython-venv/bin/activate
pip install coverage
On :ref:`most <mac-python.exe>` macOS systems run:

On :ref:`most <mac-python.exe>` macOS systems run::
.. code-block:: shell
./python.exe -m venv ../cpython-venv
source ../cpython-venv/bin/activate
pip install coverage
./python.exe -m venv ../cpython-venv
source ../cpython-venv/bin/activate
pip install coverage
On Windows run::
.. tab:: Windows

python.bat -m venv ..\\cpython-venv
..\\cpython-venv\\Scripts\\activate.bat
pip install coverage
Run:

.. code-block:: dosbatch
python.bat -m venv ..\\cpython-venv
..\\cpython-venv\\Scripts\\activate.bat
pip install coverage
You can now use python without the ./ for the rest of these instructions, as
long as your venv is activated. For more info on venv see `Virtual Environment
Expand Down Expand Up @@ -231,19 +251,49 @@ Measuring coverage of C code with gcov and lcov

It's also possible to measure the function, line and branch coverage of
Python's C code. Right now only GCC with `gcov`_ is supported. In order to
create an instrumented build of Python with gcov, run::
create an instrumented build of Python with gcov, run:

.. tab:: Unix/macOS

.. code-block:: shell
make coverage
.. tab:: Windows

make coverage
.. code-block:: dosbatch
.\make coverage
Then run some code and gather coverage data with the ``gcov`` command. In
order to create a HTML report you can install `lcov`_. The command::
order to create a HTML report you can install `lcov`_. The command:

.. tab:: Unix/macOS

.. code-block:: shell
make coverage-lcov
.. tab:: Windows

.. code-block:: dosbatch
make coverage-lcov
.\make coverage-lcov
assembles coverage data, removes 3rd party and system libraries and finally
creates a report. You can skip both steps and just run::
creates a report. You can skip both steps and just run:

.. tab:: Unix/macOS

.. code-block:: shell
make coverage-report
.. tab:: Windows

.. code-block:: dosbatch
make coverage-report
.\make coverage-report
if you like to generate a coverage report for Python's stdlib tests. It takes
about 20 to 30 minutes on a modern computer.
Expand Down

0 comments on commit 40d6473

Please sign in to comment.