15

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!

Jaykumar Patel
  • 26,836
  • 12
  • 74
  • 76
TimoSolo
  • 7,068
  • 5
  • 34
  • 50

4 Answers4

9

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!
nay
  • 864
  • 2
  • 8
  • 12
  • still no joy :( I used the --test-file param, and it is clear from the log that it ran the test twice (once for the init and once for the test-file) but no failed test and nothing in the test-report-directory.. must be something wrong with my tests or maybe I should upgrade openerp coz this should be working. – TimoSolo Feb 05 '13 at 06:22
  • I've awarded the bounty to this answer, because although still cant get it to work, it is the most complete. Thanks for your help – TimoSolo Feb 05 '13 at 07:13
  • when you say "seems to work for me" - where did you see the failed message? in the server logs? – TimoSolo Feb 05 '13 at 10:51
  • Which version of OpenERP are you using? For me too it tests 2 times. I updated my answer so that you can see the logs I get – nay Feb 05 '13 at 14:28
  • Im using v 6.1, I see yours works correctly.. I must have missed something, thanks for the feedback. – TimoSolo Feb 05 '13 at 19:52
  • I'm using v 7.0. Try to upgrade and let me know how it works for you – nay Feb 06 '13 at 19:18
4

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..

Community
  • 1
  • 1
m01
  • 9,033
  • 6
  • 32
  • 58
  • according to the docs: --log-level=LOG_LEVEL specify the level of the logging. Accepted values: ['info', 'debug_rpc', 'warn', 'test', 'critical', 'debug_sql', 'error', 'debug', 'debug_rpc_answer', 'notset'] and: --test-report-directory=TEST_REPORT_DIRECTORY If set, will save sample of all reports in this directory. tried both and no luck – TimoSolo Feb 04 '13 at 13:26
3

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.

Vedang
  • 101
  • 3
  • error: no such option: --test-enable the --test-commit has no effect, from the docs I imagine that is used to commit the db changes made by the test otherwise they are rolled back – TimoSolo Feb 04 '13 at 13:22
  • if you work on V7 then follow above option which i posted yesterday. But if you are working on 6.1 then...... used this command ./openerp-server.py --addons-path=../../addons -u -d -- test-commit – Vedang Feb 05 '13 at 09:31
  • @Timothy : when you start your server or update the module then does your .yml file load with other files? please look at once. – Vedang Feb 05 '13 at 09:36
  • I tried your suggestion. the yml file does load - it shows the "TEST testdb openerp.tools.yaml_import: I test the tests" but doesnt show any failed (or passed) test – TimoSolo Feb 05 '13 at 10:53
  • @Timothy if your test case run without any error then check in your system. demo data would be there for respective model which you write for. – Vedang Feb 06 '13 at 10:51
2

Try this in your terminal it will work.

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

Hope This will help you.

Heroic
  • 980
  • 4
  • 12