@@ -24,6 +24,7 @@ def test_db_can_be_accessed():
24
24
''' )
25
25
26
26
result = django_testdir .runpytest ('-v' , '--reuse-db' )
27
+ assert result .ret == 0
27
28
result .stdout .fnmatch_lines ([
28
29
"*test_db_can_be_accessed PASSED*" ,
29
30
])
@@ -55,6 +56,7 @@ def test_db_can_be_accessed():
55
56
# Do not pass in --create-db to make sure it is created when it
56
57
# does not exist
57
58
result_first = django_testdir .runpytest ('-v' , '--reuse-db' )
59
+ assert result_first .ret == 0
58
60
59
61
result_first .stdout .fnmatch_lines ([
60
62
"*test_db_can_be_accessed PASSED*" ,
@@ -65,6 +67,7 @@ def test_db_can_be_accessed():
65
67
assert mark_exists ()
66
68
67
69
result_second = django_testdir .runpytest ('-v' , '--reuse-db' )
70
+ assert result_second .ret == 0
68
71
result_second .stdout .fnmatch_lines ([
69
72
"*test_db_can_be_accessed PASSED*" ,
70
73
])
@@ -73,6 +76,7 @@ def test_db_can_be_accessed():
73
76
assert mark_exists ()
74
77
75
78
result_third = django_testdir .runpytest ('-v' , '--reuse-db' , '--create-db' )
79
+ assert result_third .ret == 0
76
80
result_third .stdout .fnmatch_lines ([
77
81
"*test_db_can_be_accessed PASSED*" ,
78
82
])
@@ -116,6 +120,7 @@ def test_a():
116
120
''' % (self .db_name_17 , self .db_name_before_17 ))
117
121
118
122
result = django_testdir .runpytest ('--tb=short' , '-v' )
123
+ assert result .ret == 0
119
124
result .stdout .fnmatch_lines (['*test_a*PASSED*' ])
120
125
121
126
@@ -160,6 +165,7 @@ def test_d(settings):
160
165
''' )
161
166
162
167
result = django_testdir .runpytest ('-vv' , '-n2' , '-s' , '--reuse-db' )
168
+ assert result .ret == 0
163
169
result .stdout .fnmatch_lines (['*PASSED*test_a*' ])
164
170
result .stdout .fnmatch_lines (['*PASSED*test_b*' ])
165
171
result .stdout .fnmatch_lines (['*PASSED*test_c*' ])
@@ -169,13 +175,15 @@ def test_d(settings):
169
175
assert db_exists ('gw1' )
170
176
171
177
result = django_testdir .runpytest ('-vv' , '-n2' , '-s' , '--reuse-db' )
178
+ assert result .ret == 0
172
179
result .stdout .fnmatch_lines (['*PASSED*test_a*' ])
173
180
result .stdout .fnmatch_lines (['*PASSED*test_b*' ])
174
181
result .stdout .fnmatch_lines (['*PASSED*test_c*' ])
175
182
result .stdout .fnmatch_lines (['*PASSED*test_d*' ])
176
183
177
184
result = django_testdir .runpytest ('-vv' , '-n2' , '-s' , '--reuse-db' ,
178
185
'--create-db' )
186
+ assert result .ret == 0
179
187
result .stdout .fnmatch_lines (['*PASSED*test_a*' ])
180
188
result .stdout .fnmatch_lines (['*PASSED*test_b*' ])
181
189
result .stdout .fnmatch_lines (['*PASSED*test_c*' ])
@@ -206,6 +214,7 @@ def test_a():
206
214
''' )
207
215
208
216
result = django_testdir .runpytest ('--tb=short' , '-vv' , '-n1' )
217
+ assert result .ret == 0
209
218
result .stdout .fnmatch_lines (['*PASSED*test_a*' ])
210
219
211
220
@@ -226,6 +235,7 @@ def test_inner_south():
226
235
''' )
227
236
228
237
result = django_testdir_initial .runpytest ('--tb=short' , '-v' )
238
+ assert result .ret == 0
229
239
result .stdout .fnmatch_lines (['*test_inner_south*PASSED*' ])
230
240
231
241
@@ -236,7 +246,7 @@ def test_inner_south():
236
246
@pytest .mark .skipif (sys .version_info [0 ] == 3 ,
237
247
reason = 'South is not properly supported on Python 3' )
238
248
class TestSouth :
239
- """Test interaction with initial_data and South ."""
249
+ """Test interaction with South, with and without initial_data ."""
240
250
241
251
@pytest .mark .django_project (extra_settings = """
242
252
INSTALLED_APPS += [ 'south', ]
@@ -288,6 +298,7 @@ def test_inner_south():
288
298
django_testdir_initial .mkpydir ('tpkg/app/south_migrations' )
289
299
290
300
result = django_testdir_initial .runpytest ('--tb=short' , '-v' , '-s' )
301
+ assert result .ret != 0
291
302
# Can be OperationalError or DatabaseError (Django 1.4).
292
303
result .stdout .fnmatch_lines ([
293
304
'*Error:* no such table: app_item*' ])
@@ -300,9 +311,8 @@ def test_inner_south():
300
311
}
301
312
""" )
302
313
def test_initial_south_migrations (self , django_testdir_initial ):
303
- """
304
- Test initial data with existing South migrations.
305
- """
314
+ """This should fail, because it has no real migration that
315
+ would create the table, and so no initial data can be loaded."""
306
316
testdir = django_testdir_initial
307
317
testdir .create_test_module ('''
308
318
import pytest
@@ -315,11 +325,39 @@ def test_inner_south():
315
325
testdir .create_initial_south_migration ()
316
326
317
327
result = testdir .runpytest ('--tb=short' , '-v' , '-s' )
318
- result .stdout .fnmatch_lines_random ([
319
- "tpkg/test_the_test.py::test_inner_south*" ,
320
- "*mark_south_migration_forwards*" ,
321
- "*PASSED*" ,
322
- "*Destroying test database for alias 'default'...*" ])
328
+ assert result .ret != 0
329
+ result .stderr .fnmatch_lines (['*no such table: app_item*' ])
330
+ result .stdout .fnmatch_lines (['*mark_south_migration_forwards*' ])
331
+
332
+ @pytest .mark .django_project (extra_settings = """
333
+ INSTALLED_APPS += [ 'south', ]
334
+ SOUTH_TESTS_MIGRATE = True
335
+ SOUTH_MIGRATION_MODULES = {
336
+ 'app': 'tpkg.app.south_migrations',
337
+ }
338
+ """ )
339
+ def test_south_migrations (self , django_testdir ):
340
+ """South migration with a normal testdir (no initial data)."""
341
+ testdir = django_testdir
342
+ testdir .create_test_module ('''
343
+ import pytest
344
+
345
+ @pytest.mark.django_db
346
+ def test_inner_south():
347
+ pass
348
+ ''' )
349
+
350
+ testdir .mkpydir ('tpkg/app/south_migrations' )
351
+ testdir .create_app_file ("""
352
+ from south.v2 import SchemaMigration
353
+
354
+ class Migration(SchemaMigration):
355
+ def forwards(self, orm):
356
+ print("mark_south_migration_forwards")
357
+ """ , 'south_migrations/0001_initial.py' )
358
+ result = testdir .runpytest ('--tb=short' , '-v' , '-s' )
359
+ assert result .ret == 0
360
+ result .stdout .fnmatch_lines (['*mark_south_migration_forwards*' ])
323
361
324
362
@pytest .mark .django_project (extra_settings = """
325
363
INSTALLED_APPS += [ 'south', ]
@@ -345,6 +383,7 @@ def test_inner_south():
345
383
ensure = True )
346
384
347
385
result = testdir .runpytest ('--tb=short' , '-v' , '-s' )
386
+ assert result .ret == 0
348
387
result .stdout .fnmatch_lines_random ([
349
388
"tpkg/test_the_test.py::test_inner_south*" ,
350
389
"*PASSED*" ,
@@ -380,6 +419,7 @@ def test_inner_south():
380
419
python_files=*.py""" , 'pytest.ini' )
381
420
382
421
result = testdir .runpytest ('--tb=short' , '-v' , '-s' , '-c' , pytest_ini )
422
+ assert result .ret == 0
383
423
result .stdout .fnmatch_lines_random ([
384
424
"tpkg/test.py::test_inner_south*" ,
385
425
"*mark_south_migration_forwards*" ,
@@ -408,6 +448,7 @@ def test_inner_migrations():
408
448
ensure = True )
409
449
410
450
result = testdir .runpytest ('--nomigrations' , '--tb=short' , '-v' )
451
+ assert result .ret == 0
411
452
result .stdout .fnmatch_lines (['*test_inner_migrations*PASSED*' ])
412
453
413
454
@pytest .mark .skipif (get_django_version () < (1 , 7 ),
@@ -453,4 +494,5 @@ class Migration(migrations.Migration):
453
494
]
454
495
""" , 'migrations/0001_initial.py' )
455
496
result = testdir .runpytest ('--tb=short' , '-v' , '-s' )
497
+ assert result .ret == 0
456
498
result .stdout .fnmatch_lines (['*mark_migrations_run*' ])
0 commit comments