-
Notifications
You must be signed in to change notification settings - Fork 348
Option to use one database when xdist plugin is used #336
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
Open
magicjohnson
wants to merge
9
commits into
pytest-dev:main
Choose a base branch
from
360youlun:feature/xdist-one-db
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4cf9988
added option to use one database per suite when xdist plugin is used
magicjohnson 515bd71
fix typo
magicjohnson 8010b32
make function private
magicjohnson 9119320
tests fix
magicjohnson 207254b
raise ValueError in case of usage sqlite together with --xdist-one-db
magicjohnson c7e1f25
tests to be backend-specific
magicjohnson 83ad206
make sure test database is used (not production one)
magicjohnson f56e012
_django_cursor_wrapper is essential
magicjohnson 7df098b
rename reuse_db function to not be confused with option name
magicjohnson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,13 @@ | |
import py | ||
import pytest | ||
|
||
from .db_reuse import monkey_patch_creation_for_db_reuse | ||
from .django_compat import is_django_unittest | ||
from .fixtures import (_django_db_setup, _live_server_helper, admin_client, | ||
admin_user, client, db, django_user_model, | ||
django_username_field, live_server, rf, settings, | ||
transactional_db) | ||
from .lazy_django import django_settings_is_configured, skip_if_no_django | ||
transactional_db, _handle_south, _disable_native_migrations) | ||
from .lazy_django import django_settings_is_configured, skip_if_no_django, get_django_version | ||
|
||
# Silence linters for imported fixtures. | ||
(_django_db_setup, _live_server_helper, admin_client, admin_user, client, db, | ||
|
@@ -44,6 +45,10 @@ def pytest_addoption(parser): | |
action='store_true', dest='create_db', default=False, | ||
help='Re-create the database, even if it exists. This ' | ||
'option will be ignored if not --reuse-db is given.') | ||
group._addoption('--xdist-one-db', | ||
dest='xdist_one_db', default=False, action='store_true', | ||
help="Use only one database with xdist plugin. " | ||
"Doesn't work with sqlite3 backend due to db lock") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, this implies it is true for sqlite in general - but should have a dot at the end. |
||
group._addoption('--ds', | ||
action='store', type='string', dest='ds', default=None, | ||
help='Set DJANGO_SETTINGS_MODULE.') | ||
|
@@ -246,6 +251,32 @@ def pytest_report_header(config): | |
return [config._dsm_report_header] | ||
|
||
|
||
def pytest_xdist_setupnodes(config): | ||
"""called once before any remote node is set up. """ | ||
if not config.getvalue('xdist_one_db'): | ||
return | ||
_setup_django() | ||
|
||
from django.conf import settings | ||
if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.sqlite3': | ||
return | ||
|
||
_handle_south() | ||
|
||
if config.getvalue('nomigrations'): | ||
_disable_native_migrations() | ||
|
||
db_args = {} | ||
if get_django_version() >= (1, 8): | ||
db_args['keepdb'] = True | ||
else: | ||
monkey_patch_creation_for_db_reuse() | ||
|
||
from django.test.runner import setup_databases | ||
# Create the database | ||
setup_databases(verbosity=config.option.verbose, interactive=False, **db_args) | ||
|
||
|
||
@pytest.mark.trylast | ||
def pytest_configure(): | ||
# Allow Django settings to be configured in a user pytest_configure call, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 might only be true for the
:mem:
sqlite db, no?