Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

[ADD] Fixture environment #23

wants to merge 2 commits into from

Conversation

ssaid
Copy link

@ssaid ssaid commented Jul 13, 2018

No description provided.

registry = odoo.modules.registry.RegistryManager.get(dbname)
cr = registry.cursor()
uid = odoo.SUPERUSER_ID
return odoo.api.Environment(cr, uid, {})
Copy link
Contributor

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, {})

Copy link

@dcrocco dcrocco Oct 2, 2019

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()

Copy link
Contributor

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?)?

Copy link

@dcrocco dcrocco Oct 7, 2019

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?

@simahawk
Copy link
Member

This has been created a loooong time ago. Is it still relevant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants