Skip to Content
Menu
This question has been flagged
1 Reply
5493 Views
Hi Guys 

I was trying to use the python package (coverage) to check unit test coverage in odoo but i don't know how to use it with odoo, for example :

def test_18_functionality:
import coverage

cov = coverage.Coverage()
cov.start()
# call testing methods ....
cov.stop()
cov.save()
cov.html_report()

is there any idea on how to check that i covered my unit tests ?

Thanks

Avatar
Discard
Best Answer

Hi Ahmed,

Refer to the doc  https://coverage.readthedocs.io/en/v4.5.x/  

Thanks.

Avatar
Discard
Author

Hi,

I already checked it ... i just want to know to call this :

cov = coverage.Coverage()

cov.start()

# call testing methods ....

cov.stop()

cov.save()

cov.html_report()

in the right position to get the right report coverage ?

Thanks

Hi,

Follow the steps:

1.) Install sudo pip3 coverage

2.) covergae run ./odoo-bin --addons-path=addons --db-filter=yourdatabase --xmlrpc-port=8012 -d yourdatabase -u your_module --test-enable --log-level=test

Author

Thanks, that works fine :)

Just a hint ... we should use coverage3 for ODOO 11 and above instead of coverage

coverage3 run ./odoo-bin --addons-path=addons --db-filter=yourdatabase --xmlrpc-port=8012 -d yourdatabase -u your_module --test-enable --log-level=test

No, you can't do it.

Author

If you have python 2.7 on your machine and installed coverage and then run :

coverage run ./odoo-bin --addons-path=addons --db-filter=yourdatabase --xmlrpc-port=8012 -d yourdatabase -u your_module --test-enable --log-level=test

It will use coverage for python 2.7

Check this https://coverage.readthedocs.io/en/v4.5.x/cmd.html

They say :

When you install coverage.py, a command-line script simply called coverage is placed in your Python scripts directory. To help with multi-version installs, it will also create either a coverage2 or coverage3 alias, and a coverage-X.Y alias, depending on the version of Python you’re using. For example, when installing on Python 2.7, you will be able to use coverage, coverage2, or coverage-2.7 on the command line.

Related Posts Replies Views Activity
0
Jun 22
1693
2
Nov 24
272
1
Oct 24
335
4
Oct 24
326
2
Oct 24
362