-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ADD] Fixture environment #23
base: master
Are you sure you want to change the base?
Conversation
registry = odoo.modules.registry.RegistryManager.get(dbname) | ||
cr = registry.cursor() | ||
uid = odoo.SUPERUSER_ID | ||
return odoo.api.Environment(cr, uid, {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should surround the environment with a odoo.api.Environment.manage():
context manager:
with odoo.api.Environment.manage():
yield odoo.api.Environment(cr, uid, {})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guewen I think this fixture is pretty usefull for bdd with pytest-bdd, want me to re-open this with this?:
@pytest.fixture(scope='session', autouse=True)
def env():
db_name = odoo.tests.common.get_db_name()
registry = odoo.registry(db_name)
cr = registry.cursor()
with odoo.api.Environment.manage():
env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {})
yield env
registry.clear_caches()
registry.reset_changes()
env.reset()
cr.rollback()
cr.close()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it has autouse=True
, it means it will always be used right? Can you explain me what does it change compared to the current behavior and what would this fixture bring (which use case?)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but it will run only once.
I’m using it when i need the odoo enviroment and i’m not inheriting from odoo test clases, for example when doing integration tests cross-modules (in my case i’m using pytest-bdd, and i need it for a lot of scenarios).
Else, you will always need to inherit from odoo test classes or set up this in every scenario.
What do you think?
This has been created a loooong time ago. Is it still relevant? |
No description provided.