Question

I'm trying to run unit tests on my openERP module, but no matter what I write it doesnt show if the test passes or fails! Anyone know how to output the results of a test? (Using Windows OpenERP version 6.1)

My YAML test is:

- 
  I test the tests
-
  !python {model: mymodelname}: |
    assert False, "Testing False!"
    assert True, "Testing True!"

The output when I reload the module with openerp-server.exe --update mymodule --log-level=test -dtestdb shows that the test ran but has no errors?!

... TEST testdb openerp.tools.yaml_import: I test the tests

What am I doing wrong?

Edit: ---------------------------------------------------------------------

Ok so after much fiddling with the !python, I tried out another test:

- 
    I test that the state
-
!assert {model: mymodel, id: mymodel_id}:
    - state == 'badstate'

Which gave the expected failure:

WARNING demo_61 openerp.tools.yaml_import: Assertion "NONAME" FAILED
test: state == 'badstate'
values: ! active == badstate

So I'm guessing it is something wrong with my syntax which may work as expected in version 7.

Thanks for everyone's answers and help!

Était-ce utile?

La solution

This is what I've tried. It seems to work for me:

!python {model: sale.order}: |
    assert True, "Testing True!"
    assert False, "Testing False!"

(Maybe you forgot the "|" character)

And then :

bin/start_openerp --init=your_module_to_test -d your_testing_database --test-file=/absolute/path/to/your/testing_file.yml

You might want to create your testing database before :

createdb mytestdb --encoding=unicode

Hope it helps you

UPDATE: Here are my logs ( I called my test file sale_order_line_test.yml)

ERROR mytestdb openerp.tools.yaml_import: AssertionError in Python code : Testing False!
mytestdb openerp.modules.loading: At least one test failed when loading the modules.
loading test file /path/to/module/test/sale_order_line_test.yml
AssertionError in Python code : Testing False!

Autres conseils

Looking at the docs (e.g. here and here), I can't see anything obviously wrong with your code.

However, I'm not familiar with --log-level=test. Maybe try running it with the -v, --debug or --log-level=debug flags instead of --log-level=test? You may also need to try the uppercase variants for the --log-level argument, i.e. --log-level=DEBUG.

test certainly isn't one of the standard Python logging module's logging levels, and while I can't exclude the possibility of them adding a custom log level, I don't think that's the case.

It might also be worthwhile trying to remove the line obj = self.browse(cr, uid, ref("HP001")), just in case..

Try to type following path on your terminal when you start your server.

./openerp-server --addons-path=<..Path>...--test-enable

:Enable YAML and unit tests.

./openerp-server --addons-path=<..Path>...--test-commit

:Commit database changes performed by YAML or XML tests.

Try this in your terminal it will work.

./openerp-server --addons-path=<..Path> --log-level=test --test-enable

Hope This will help you.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top