-
Notifications
You must be signed in to change notification settings - Fork 53
Description
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?