-
Notifications
You must be signed in to change notification settings - Fork 348
Support reset_sequences #308
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
Changes from 7 commits
51bd265
3cad678
df1bbdb
8c0dce4
9b7ec4b
e45daf3
50001d3
216757f
def0121
c6ec611
3e3287a
add9d49
eaa5e7b
da378e2
a756f4e
0bfb9af
b74c28d
28a3876
f8d2e1d
fd3603a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,10 @@ | |
from .django_compat import is_django_unittest | ||
from .lazy_django import get_django_version, skip_if_no_django | ||
|
||
__all__ = ['_django_db_setup', 'db', 'transactional_db', 'admin_user', | ||
'django_user_model', 'django_username_field', | ||
'client', 'admin_client', 'rf', 'settings', 'live_server', | ||
'_live_server_helper'] | ||
__all__ = ['_django_db_setup', 'db', 'transactional_db', | ||
'reset_sequences_db', 'admin_user', 'django_user_model', | ||
'django_username_field', 'client', 'admin_client', 'rf', | ||
'settings', 'live_server', '_live_server_helper'] | ||
|
||
|
||
# ############### Internal Fixtures ################ | ||
|
@@ -64,7 +64,10 @@ def teardown_database(): | |
request.addfinalizer(teardown_database) | ||
|
||
|
||
def _django_db_fixture_helper(transactional, request, _django_cursor_wrapper): | ||
def _django_db_fixture_helper(request, _django_cursor_wrapper, | ||
transactional=False, reset_sequences=False): | ||
"""Setup the django test case and pytest execution context.""" | ||
|
||
if is_django_unittest(request): | ||
return | ||
|
||
|
@@ -83,6 +86,10 @@ def _django_db_fixture_helper(transactional, request, _django_cursor_wrapper): | |
if get_version() >= '1.5': | ||
from django.test import TransactionTestCase as django_case | ||
|
||
if reset_sequences: | ||
class ResetSequenceTestCase(django_case): | ||
reset_sequences = True | ||
django_case = ResetSequenceTestCase | ||
else: | ||
# Django before 1.5 flushed the DB during setUp. | ||
# Use pytest-django's old behavior with it. | ||
|
@@ -107,6 +114,7 @@ def flushdb(): | |
case = django_case(methodName='__init__') | ||
case._pre_setup() | ||
request.addfinalizer(case._post_teardown) | ||
return django_case | ||
|
||
|
||
def _handle_south(): | ||
|
@@ -177,7 +185,7 @@ def db(request, _django_db_setup, _django_cursor_wrapper): | |
if 'transactional_db' in request.funcargnames \ | ||
or 'live_server' in request.funcargnames: | ||
return request.getfuncargvalue('transactional_db') | ||
return _django_db_fixture_helper(False, request, _django_cursor_wrapper) | ||
return _django_db_fixture_helper(request, _django_cursor_wrapper) | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
|
@@ -192,7 +200,25 @@ def transactional_db(request, _django_db_setup, _django_cursor_wrapper): | |
database setup will behave as only ``transactional_db`` was | ||
requested. | ||
""" | ||
return _django_db_fixture_helper(True, request, _django_cursor_wrapper) | ||
return _django_db_fixture_helper(request, _django_cursor_wrapper, | ||
transactional=True) | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def reset_sequences_db(request, _django_db_setup, _django_cursor_wrapper): | ||
"""Require a transactional test database with sequence reset support | ||
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. Please add punctuation (a dot) at the end. 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. done |
||
|
||
This behaves like the ``transactional_db`` fixture, with the addition | ||
of enforcing a reset of all auto increment sequence. If the enquiring | ||
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. s/sequence/sequences/ 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. done |
||
test relies on such values (e.g. ids as primary keys), you should | ||
request this resource to ensure they are consistent across tests. | ||
|
||
If a combination of this, ``db`` and ``transactional_db`` is requested | ||
then the database setup will behave as only ``reset_sequences_db`` | ||
was requested. | ||
""" | ||
return _django_db_fixture_helper(request, _django_cursor_wrapper, | ||
transactional=True, reset_sequences=True) | ||
|
||
|
||
@pytest.fixture() | ||
|
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.
s/mark.django_db/mark.reset_sequences_db/
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.
I am sorry, I don't understand 😕 Is that sphinx syntax?
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.
No,
sed
.. ;)Change "mark.django_db" to "mark.reset_sequences_db".
It seems you have copied it from the paragraph above, but it should be changed here - if I understand it correctly.
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.
Ahh okay 😌 ! There is only one marker (
django_db
), but it has some optional keywords that make the difference. I updated that section of the docs to make it clear which one to use for a test to get the same effect as using the fixture.