-
Notifications
You must be signed in to change notification settings - Fork 46
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 support for distributed run #77
Conversation
When tests are distributed, a copy of the database is created for each worker at the start of the test session. This is useful to avoid concurrent access to the same database, which can lead to deadlocks. The provided database is therefore used only as template. At the end of the tests, all the created databases are dropped.
4e02c7f
to
9ee223f
Compare
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #77 +/- ##
=========================================
Coverage ? 33.65%
=========================================
Files ? 1
Lines ? 104
Branches ? 0
=========================================
Hits ? 35
Misses ? 69
Partials ? 0 ☔ View full report in Codecov by Sentry. |
ping @yvaucher |
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.
Code looks good to me. I Haven't test. I would love to see some kind of unittest but integration test would get more value here which is a bit annoyed to setup so won't lock on that here.
pytest_odoo.py
Outdated
ret = os.system(f"psql -lqt | cut -d \| -f 1 | grep -w {db_name}") | ||
if ret == 0: | ||
os.system(f"dropdb {db_name}") | ||
os.system(f"createdb -T {original_db_name} {db_name}") |
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.
this sounds a very opinionated way to connect to the database, probably we should at least add such limitation in the Readme file or read odoo config file to retrieves host and credentials informations
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 can already configure psql with env var to get to the right config with PGDATABASE, PGUSER, PGHOST and so on. Using psql
, dropdb
and createdb
without params seems fine to me.
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 indeed 👍 !
@lmignon should we add a note on Did you test it? It groups tests by class to send related tests to the same worker (thus I would assume on the same DB), it might be a bit for efficient with Savepoints? https://pytest-xdist.readthedocs.io/en/stable/changelog.html#id189 |
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.
Looks great
Code review only need to test that.
Co-authored-by: Yannick Payot <[email protected]>
320b456
to
0168a0e
Compare
@yvaucher I've just tested it following your comment. I didn't notice any significant difference between the different ways of distributing tests between workers. |
Played a bit with it, and works fine, let's merge this. I'll create a small release to make it available. |
When tests are distributed, a copy of the database is created for each worker at the start of the test session. This is useful to avoid concurrent access to the same database, which can lead to deadlocks. The provided database is therefore used only as template. At the end of the tests, all the created databases are dropped.