Skip to content

(Discussion) Reused DB Template Load Factory #1243

Description

@ivanthewebber

I wanted to poll your experience on a couple possible improvements.

Currently the load logic would be ran once per database creating a template for each, but for most users it probably only needs ran once for a single template that can be reused. Thus, I think a helper load factory function could be useful to deduplicate. It might look like following pseudocode:

import multiprocessing

def init_db_factory(load_template: callable):
    template_ready = multiprocessing.Value('b', False)

    def check_bool():
           if not template_ready:
               raise ValueError()

    def inner(*args, **kwargs):
        if not os.getenv("PYTEST_XDIST_WORKER"):
            # initialize db template as usual
            load_template(*args, **kwargs)
            template_ready.set(True)
        else:
            # wait for template to exist
            retry(check_bool, possible_exception=ValueError)

Of course some other logic/config to reuse the template name might need adjusted.

What are your thoughts?

Additionally I've observed that the template approach might be slower for the many tables in our database, do you have thoughts on that? Perhaps being able to toggle easily would make the library more useful and easier to find the best configuration for a project's individual differences.

Finally, we already have a lot of fixtures that are often reused that add some data into the database/session for testing. My understanding is that replacing these with pre-populated data in the template DB should give us some test suite speed improvements?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions