coverage.py

How to properly use coverage.py in Python?

不羁的心 提交于 2019-11-29 23:44:36
I've just started using Coverage.py module and so decided to make a simple test to check how it works. Sample.py def sum(num1, num2): return num1 + num2 def sum_only_positive(num1, num2): if num1 > 0 and num2 > 0: return num1 + num2 else: return None test.py from sample import sum, sum_only_positive def test_sum(): assert sum(5, 5) == 10 def test_sum_positive_ok(): assert sum_only_positive(2, 2) == 4 def test_sum_positive_fail(): assert sum_only_positive(-1, 2) is None As you see, all my code is covered with tests and py.test says all of them pass. I expect Coverage.py to show 100% coverage.

Running coverage inside virtualenv

陌路散爱 提交于 2019-11-29 11:50:10
问题 I recently stumbled upon some issue with running coverage measurements within virtual environment. I do not remember similar issues in the past, nor I was able to find solution on the web. Basically, when I am trying to run test suite in virtualenv, it works fine. But as soon, as I try to do it using coverage , it fails because of lack of modules it requires. Based on some answer on StackOverflow I checked my script and found out that coverage uses different interpreter, even if running from

Flask Testing - why does coverage exclude import statements and decorators?

喜欢而已 提交于 2019-11-29 11:46:22
问题 My tests clearly execute each function, and there are no unused imports either. Yet, according to the coverage report, 62% of the code was never executed in the following file: Can someone please point out what I might be doing wrong? Here's how I initialise the test suite and the coverage: cov = coverage(branch=True, omit=['website/*', 'run_test_suite.py']) cov.start() try: unittest.main(argv=[sys.argv[0]]) except: pass cov.stop() cov.save() print "\n\nCoverage Report:\n" cov.report() print

Finding unused Django code to remove

大憨熊 提交于 2019-11-29 00:05:44
问题 I've started working on a project with loads of unused legacy code in it. I was wondering if it might be possible to use a tool like coverage in combination with a crawler (like the django-test-utils one) to help me locate code which isn't getting hit which we can mark with deprecation warnings. I realise that something like this won't be foolproof but thought it might help. I've tried running coverage.py with the django debug server but it doesn't work correctly (it seems to just profile the

Using py.test with coverage doesn't include imports

那年仲夏 提交于 2019-11-28 20:06:09
For Jedi we want to generate our test coverage . There is a related question in stackoverflow, but it didn't help. We're using py.test as a test runner. However, we are unable to add the imports and other "imported" stuff to the report. For example __init__.py is always reported as being uncovered: Name Stmts Miss Cover -------------------------------------------------- jedi/__init__ 5 5 0% [..] Clearly this file is being imported and should therefore be reported as tested. We start tests like this [*]: py.test --cov jedi As you can see we're using pytest-coverage . So how is it possible to

How to get coverage data from a django app when running in gunicorn

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 09:12:49
How do I get code coverage out of a Django project's view code (and code called by view code)? coverage gunicorn <params> does not show any lines being hit. coverage gunicorn <params> does not work, because gunicorn creates worker processes, and the coverage module can't work across forks (basically, creation of new processes). You can use the coverage API , though, for example in the python module that contains your WSGI application: # wsgi_with_coverage.py import atexit import sys import coverage cov = coverage.coverage() cov.start() from wsgi import application # adjust to python module

Why doesn't coverage.py properly measure Django's runserver command?

一曲冷凌霜 提交于 2019-11-27 20:35:02
问题 I should know the answer to this, but I don't: if you try to measure the coverage of a Django project like this: coverage run manage.py runserver you get coverage measurement that misses all of your actual code. Something early on in the process is stopping the measurement, or all the real work happens in a new context that doesn't get measured at all. Can someone point me to the specific point in the process where the measurement breaks down, so that I can try to fix coverage.py so that it

Django coverage test for URLs 0%, why?

给你一囗甜甜゛ 提交于 2019-11-27 18:58:25
问题 Using Django Nose. I have tests for my URL's but coverage is still giving me 0% for URLs, why? python manage.py test profiles This is my coverage: Name Stmts Miss Cover Missing ---------------------------------------------------------------- profiles 0 0 100% profiles.migrations 0 0 100% profiles.migrations.0001_initial 6 0 100% profiles.models 0 0 100% profiles.urls 4 4 0% 1-9 ---------------------------------------------------------------- TOTAL 10 4 60% ------------------------------------