coverage.py

Specifying Location of Code Coverage Data FIle

痞子三分冷 提交于 2021-02-11 15:10:36
问题 I'm trying to integrate code coverage with Travis CI for a python repository. In the project root, my .coveragerc looks like: [run] data_file = tests/coverage/.coverage omit = data-structures/lib/* [html] directory = tests/coverage/html_report/ [xml] output = tests/coverage/coverage.xml All the attributes are reflected correctly except data_file . I see a reports file created under tests/ . I have also tried data_file = tests/coverage/ , but the reports file is still created under tests/ .

python代码覆盖率coverage简介与用法

ぐ巨炮叔叔 提交于 2021-02-08 19:59:19
如果衡量单元测试对相应代码的测试重量,覆盖率是一个必要非充分条件,因此统计代码的覆盖率,检视单测是否充分,就尤为的重要。 这里针对python-unittest的单测的覆盖率coverage进行使用说明与分析. 参考链接: https://blog.csdn.net/xiaoxinyu316/article/details/53695342 coverage简介: coverage是一种用于统计Python代码覆盖率的工具,通过它可以检测测试代码对被测代码的覆盖率如何。可以高亮显示代码中哪些语句未被执行,哪些执行了,方便单测。并且,coverage支持分支覆盖率统计,可以生成HTML/XML报告 。 官方文档: http://coverage.readthedocs.org/en/latest/ 获取地址: http://pypi.python.org/pypi/coverage 使用coverage统计代码覆盖率的步骤: 安装coverage包: pip install coverage 在源代码的根目录的路径下面,添加文件‘.coveragerc.py’ 1 # 文件中的代码为: 2 [run] 3 branch = True 4 source = xxx # 项目名称xxx 进入当前待执行的文件路径下面 执行 coverage run --help    # 打印帮助信息

Tox 0% coverage

别来无恙 提交于 2021-02-07 12:24:17
问题 I have a python project where I use: pipenv tox pytest and many more. Basically, I want to add tox to my gitlab pipelines. And almost everything seems to work, calling mypy , flake8 or black from tox works fine. But when I call tox -e py37 (so I want to run the tests) with coverage enabled, the tests are run, I can see their results, but the coverage is 0% ( 100% only on empty __init__ files etc.) and I get the warning: Coverage.py warning: No data was collected. (no-data-collected) . This is

Why does Coverage.py ignore files with no coverage?

爷,独闯天下 提交于 2020-06-27 11:18:10
问题 I first run nosetests --with-coverage So I should have a .coverage file with all the default settings. Within folder_1, I have file_1.py, file_2.py, and file_3.py When I cd into folder_1 and run coverage report It outputs: It doesn't generate anything for file_3.py! But then when I run: coverage report file_3.py it says: Does it skip files with no coverage in the report? How can I change it so the report shows me the results of every *.py file? 回答1: You need to specify a source directory for

Why does Coverage.py ignore files with no coverage?

眉间皱痕 提交于 2020-06-27 11:17:10
问题 I first run nosetests --with-coverage So I should have a .coverage file with all the default settings. Within folder_1, I have file_1.py, file_2.py, and file_3.py When I cd into folder_1 and run coverage report It outputs: It doesn't generate anything for file_3.py! But then when I run: coverage report file_3.py it says: Does it skip files with no coverage in the report? How can I change it so the report shows me the results of every *.py file? 回答1: You need to specify a source directory for

Coverage.py does not discover tests without init.py file in sub directories

☆樱花仙子☆ 提交于 2020-05-29 10:31:30
问题 When I run coverage for python, I always need an empty __init__.py file in the tests sub-directory to get coverage to run the tests. This is a requirement for python2 packages, but not for python3. To reproduce, I did the following (pre-requisites are python3, pip3 and brew): Run the following terminal command: pip3 install coverage Create the following directory structure: example\ example.py tests\ test_example.py example.py: #!/usr/bin/env python3 class Example: value = 3 def update(self):

How to measure coverage when using multirpocessing via pytest?

大憨熊 提交于 2020-04-16 05:12:47
问题 I run my unit tests via pytest. For coverage I use coverage.py. In one of my unit tests, I run a function via multirpocessing and the coverage does not reflect the functions running via multirpocessing , but the asserts work. That's the problem I am trying to solve. The test looks like so: import time import multiprocessing def test_a_while_loop(): # Start through multiprocessing in order to have a timeout. p = multiprocessing.Process( target=foo name="Foo", ) try: p.start() # my timeout time

How to measure coverage when using multirpocessing via pytest?

前提是你 提交于 2020-04-16 05:09:13
问题 I run my unit tests via pytest. For coverage I use coverage.py. In one of my unit tests, I run a function via multirpocessing and the coverage does not reflect the functions running via multirpocessing , but the asserts work. That's the problem I am trying to solve. The test looks like so: import time import multiprocessing def test_a_while_loop(): # Start through multiprocessing in order to have a timeout. p = multiprocessing.Process( target=foo name="Foo", ) try: p.start() # my timeout time

Using omit flag in Python coverage.py API

三世轮回 提交于 2020-04-12 18:53:07
问题 I'm using the python coverage.py to create a very basic test suite with coverage. Currently everything works great. However, my coverage report includes all the /usr/local/lib libraries that are called and all the __init__.py files. Here's what my coverage report call looks like right now: self.cov.html_report(directory='coverage', omit='*Test*, */usr/local/lib*,*__init__*') The goal is to use the omit flag to remove all classes with the word "Test", "/usr/local/lib", or "__init__" in them.