How to run Odoo tests unittest2?

2020-07-18 08:56发布

问题:

I tried running odoo tests using --test-enable, but it won't work. I have a couple of questions.

According to the documentation Tests can only be run during module installation, what happens when we add functionality and then want to run tests?

Is it possible to run tests from IDE like Pycharm ?

回答1:

@aftab You need add log-level please see below.

./odoo.py -d <dbname> --test-enable --log-level=test

and regarding you question, If you are making changes to installed modules and need to re test all test cases then you need to simple restart you server with -u <module_name> or -u all(for all modules) with the above command.



回答2:

This useful For Run odoo test case:

./odoo.py -i/-u module_being_tested -d being_used_to_test --test-enable

Common options:

 -i INIT, --init=INIT
       install one or more modules (comma-separated list, use "all" for all modules), requires -d

-u UPDATE, --update=UPDATE
       update one or more modules (comma-separated list, use "all" for all modules). Requires -d.

Database related options:

-d DB_NAME, --database=DB_NAME
       specify the database name

Testing Configuration:

 --test-enable:  Enable YAML and unit tests.


回答3:

Here is a REALLY nice plugin to run unit odoo tests directly with pytest:

https://github.com/camptocamp/pytest-odoo

Here's a result example: