Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
6576 Vues
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
Ignorer
Meilleure réponse

Hi Ahmed,

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

Thanks.

Avatar
Ignorer
Auteur

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

Auteur

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.

Auteur

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.

Publications associées Réponses Vues Activité
0
juin 22
2496
1
juil. 25
425
1
juin 25
1049
0
mai 25
1169
2
avr. 25
3158