diff --git a/avocado/plugins/runners/python_unittest.py b/avocado/plugins/runners/python_unittest.py index c9a717efbe..de26d273d1 100644 --- a/avocado/plugins/runners/python_unittest.py +++ b/avocado/plugins/runners/python_unittest.py @@ -109,7 +109,16 @@ def _run_unittest(cls, module_path, module_class_method, queue): return runner = TextTestRunner(stream=stream, verbosity=0) - unittest_result = runner.run(suite) + # running the actual test + if "COVERAGE_RUN" in os.environ: + from coverage import Coverage + + coverage = Coverage(data_suffix=True) + with coverage.collect(): + unittest_result = runner.run(suite) + coverage.save() + else: + unittest_result = runner.run(suite) unittest_result_entries = None if len(unittest_result.errors) > 0: diff --git a/docs/source/guides/writer/chapters/integrating.rst b/docs/source/guides/writer/chapters/integrating.rst index adc169d98d..67c880982b 100644 --- a/docs/source/guides/writer/chapters/integrating.rst +++ b/docs/source/guides/writer/chapters/integrating.rst @@ -10,7 +10,7 @@ like which parts are being exercised by the tests, may help develop new tests. `Coverage.py`_ is a tool designed for measuring code coverage of Python programs. It runs monitoring the program's source, taking notes of which parts of the code have been executed. It is possible to use Coverage.py while -running Avocado Instrumented tests. +running Avocado Instrumented tests or Python unittests. To make the Coverage.py parameters visible to other processes spawned by Avocado, create the ``.coveragerc`` file in the project's root folder and set