@@ -83,7 +83,7 @@ def test_transactions_enabled_via_reset_seq(
83
83
84
84
assert not connection .in_atomic_block
85
85
86
- def test_django_db_reset_sequences_fixture (
86
+ def test_django_db_reset_sequences_fixture_requested (
87
87
self , db , django_testdir , non_zero_sequences_counter ):
88
88
89
89
if not db_supports_reset_sequences ():
@@ -96,10 +96,6 @@ def test_django_db_reset_sequences_fixture(
96
96
import pytest
97
97
from .app.models import Item
98
98
99
- def test_django_db_reset_sequences_not_requested(db):
100
- item = Item.objects.create(name='new_item')
101
- assert item.id > 1
102
-
103
99
def test_django_db_reset_sequences_requested(
104
100
django_db_reset_sequences):
105
101
item = Item.objects.create(name='new_item')
@@ -108,10 +104,32 @@ def test_django_db_reset_sequences_requested(
108
104
109
105
result = django_testdir .runpytest_subprocess ('-v' , '--reuse-db' )
110
106
result .stdout .fnmatch_lines ([
111
- "*test_django_db_reset_sequences_not_requested PASSED*" ,
112
107
"*test_django_db_reset_sequences_requested PASSED*" ,
113
108
])
114
109
110
+ def test_django_db_reset_sequences_fixture_not_requested (
111
+ self , db , django_testdir , non_zero_sequences_counter ):
112
+
113
+ if not db_supports_reset_sequences ():
114
+ pytest .skip ('transactions and reset_sequences must be supported '
115
+ 'by the database to run this test' )
116
+
117
+ # The test runs on a database that already contains objects, so its
118
+ # id counter is > 1. We check for the ids of newly created objects.
119
+ django_testdir .create_test_module ('''
120
+ import pytest
121
+ from .app.models import Item
122
+
123
+ def test_django_db_reset_sequences_not_requested(db):
124
+ item = Item.objects.create(name='new_item')
125
+ assert item.id > 1
126
+ ''' )
127
+
128
+ result = django_testdir .runpytest_subprocess ('-v' , '--reuse-db' )
129
+ result .stdout .fnmatch_lines ([
130
+ "*test_django_db_reset_sequences_not_requested PASSED*" ,
131
+ ])
132
+
115
133
@pytest .fixture
116
134
def mydb (self , all_dbs ):
117
135
# This fixture must be able to access the database
0 commit comments