camptocamp/pytest-odoo

Easy access to ORM Environment?

erkesado opened this issue · 4 comments

First of all, thanks for a great pytest plugin.
I wonder if there is an easy way to access to ORM Environment like self.env['res.users'] ....
I have searched in pytest_odoo.py file. But I can't find anything related to the access of ORM Environment.
If it does not have an easy way of accessing ORM Environment right, I guess it should be right in the pytest-odoo. It is mindless to develop an another pytest plugin. It is mindless to copy/paste in every module.
If there is no such thing yet, I am eager to help doing it in the pytest-odoo.

Can you tell me more about your usage of pytest-odoo? Do you run "pytest" tests with it?

The use case the lib tries to cover now is to run the tests built in odoo addons which are using python's unittest, but with the comfort of the pytest CLI. These odoo's unittest tests classes already include all the boilerplate to open a cursor, environment and so on.

I do prefer a lot pytest tests over unittest, but we solely use the latter inside Odoo addons because they can also be run by the odoo machinery (--test-enable) (but also to benefit from some base tests classes that we can inherit from).

Thinking about it, there is probably a way to run pytest tests from a unittest class, which would allow to write tests as pytest but make them available from --test-enable.

So I'm looking forward to discussing your usage :)

We used to use unittest in Odoo addons. But now we prefer pytest. We will use pytest in all our Odoo modules and convert existing unittest code to pytest. I think pure pytest is better. Running pytest inside a unittest class will blur simplicity and easiness of pytest. The another reason for shifting to pytest from unittest is that we are implementing BDD in Odoo development. pytest supports BDD through pytest-bdd and Odoo supports pytest through pytest-odoo.
Even though our usage of pytest-odoo is 0% now, it will be 100% for our modules soon.

@erkesado Would you mind on giving an example of how you want to use it?

IMHO to write pytest tests for your own addons.