Skip to content

Commit c380ae2

Browse files
committed
Merge branch 'tests-check-more-ret'
Closes: pytest-dev#205
2 parents 4f9b581 + 44d4dfb commit c380ae2

File tree

6 files changed

+67
-10
lines changed

6 files changed

+67
-10
lines changed

pytest_django/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def _handle_south():
107107
# if `south` >= 0.7.1 we can use the test helper
108108
from south.management.commands import patch_for_test_db_setup
109109
except ImportError:
110-
# if `south` < 0.7.1 make sure it's migrations are disabled
110+
# if `south` < 0.7.1 make sure its migrations are disabled
111111
management.get_commands()
112112
management._commands['syncdb'] = 'django.core'
113113
else:

tests/test_db_setup.py

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def test_db_can_be_accessed():
2424
''')
2525

2626
result = django_testdir.runpytest('-v', '--reuse-db')
27+
assert result.ret == 0
2728
result.stdout.fnmatch_lines([
2829
"*test_db_can_be_accessed PASSED*",
2930
])
@@ -55,6 +56,7 @@ def test_db_can_be_accessed():
5556
# Do not pass in --create-db to make sure it is created when it
5657
# does not exist
5758
result_first = django_testdir.runpytest('-v', '--reuse-db')
59+
assert result_first.ret == 0
5860

5961
result_first.stdout.fnmatch_lines([
6062
"*test_db_can_be_accessed PASSED*",
@@ -65,6 +67,7 @@ def test_db_can_be_accessed():
6567
assert mark_exists()
6668

6769
result_second = django_testdir.runpytest('-v', '--reuse-db')
70+
assert result_second.ret == 0
6871
result_second.stdout.fnmatch_lines([
6972
"*test_db_can_be_accessed PASSED*",
7073
])
@@ -73,6 +76,7 @@ def test_db_can_be_accessed():
7376
assert mark_exists()
7477

7578
result_third = django_testdir.runpytest('-v', '--reuse-db', '--create-db')
79+
assert result_third.ret == 0
7680
result_third.stdout.fnmatch_lines([
7781
"*test_db_can_be_accessed PASSED*",
7882
])
@@ -116,6 +120,7 @@ def test_a():
116120
''' % (self.db_name_17, self.db_name_before_17))
117121

118122
result = django_testdir.runpytest('--tb=short', '-v')
123+
assert result.ret == 0
119124
result.stdout.fnmatch_lines(['*test_a*PASSED*'])
120125

121126

@@ -160,6 +165,7 @@ def test_d(settings):
160165
''')
161166

162167
result = django_testdir.runpytest('-vv', '-n2', '-s', '--reuse-db')
168+
assert result.ret == 0
163169
result.stdout.fnmatch_lines(['*PASSED*test_a*'])
164170
result.stdout.fnmatch_lines(['*PASSED*test_b*'])
165171
result.stdout.fnmatch_lines(['*PASSED*test_c*'])
@@ -169,13 +175,15 @@ def test_d(settings):
169175
assert db_exists('gw1')
170176

171177
result = django_testdir.runpytest('-vv', '-n2', '-s', '--reuse-db')
178+
assert result.ret == 0
172179
result.stdout.fnmatch_lines(['*PASSED*test_a*'])
173180
result.stdout.fnmatch_lines(['*PASSED*test_b*'])
174181
result.stdout.fnmatch_lines(['*PASSED*test_c*'])
175182
result.stdout.fnmatch_lines(['*PASSED*test_d*'])
176183

177184
result = django_testdir.runpytest('-vv', '-n2', '-s', '--reuse-db',
178185
'--create-db')
186+
assert result.ret == 0
179187
result.stdout.fnmatch_lines(['*PASSED*test_a*'])
180188
result.stdout.fnmatch_lines(['*PASSED*test_b*'])
181189
result.stdout.fnmatch_lines(['*PASSED*test_c*'])
@@ -206,6 +214,7 @@ def test_a():
206214
''')
207215

208216
result = django_testdir.runpytest('--tb=short', '-vv', '-n1')
217+
assert result.ret == 0
209218
result.stdout.fnmatch_lines(['*PASSED*test_a*'])
210219

211220

@@ -226,6 +235,7 @@ def test_inner_south():
226235
''')
227236

228237
result = django_testdir_initial.runpytest('--tb=short', '-v')
238+
assert result.ret == 0
229239
result.stdout.fnmatch_lines(['*test_inner_south*PASSED*'])
230240

231241

@@ -236,7 +246,7 @@ def test_inner_south():
236246
@pytest.mark.skipif(sys.version_info[0] == 3,
237247
reason='South is not properly supported on Python 3')
238248
class TestSouth:
239-
"""Test interaction with initial_data and South."""
249+
"""Test interaction with South, with and without initial_data."""
240250

241251
@pytest.mark.django_project(extra_settings="""
242252
INSTALLED_APPS += [ 'south', ]
@@ -288,6 +298,7 @@ def test_inner_south():
288298
django_testdir_initial.mkpydir('tpkg/app/south_migrations')
289299

290300
result = django_testdir_initial.runpytest('--tb=short', '-v', '-s')
301+
assert result.ret != 0
291302
# Can be OperationalError or DatabaseError (Django 1.4).
292303
result.stdout.fnmatch_lines([
293304
'*Error:* no such table: app_item*'])
@@ -300,9 +311,8 @@ def test_inner_south():
300311
}
301312
""")
302313
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."""
306316
testdir = django_testdir_initial
307317
testdir.create_test_module('''
308318
import pytest
@@ -315,11 +325,39 @@ def test_inner_south():
315325
testdir.create_initial_south_migration()
316326

317327
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*'])
323361

324362
@pytest.mark.django_project(extra_settings="""
325363
INSTALLED_APPS += [ 'south', ]
@@ -345,6 +383,7 @@ def test_inner_south():
345383
ensure=True)
346384

347385
result = testdir.runpytest('--tb=short', '-v', '-s')
386+
assert result.ret == 0
348387
result.stdout.fnmatch_lines_random([
349388
"tpkg/test_the_test.py::test_inner_south*",
350389
"*PASSED*",
@@ -380,6 +419,7 @@ def test_inner_south():
380419
python_files=*.py""", 'pytest.ini')
381420

382421
result = testdir.runpytest('--tb=short', '-v', '-s', '-c', pytest_ini)
422+
assert result.ret == 0
383423
result.stdout.fnmatch_lines_random([
384424
"tpkg/test.py::test_inner_south*",
385425
"*mark_south_migration_forwards*",
@@ -408,6 +448,7 @@ def test_inner_migrations():
408448
ensure=True)
409449

410450
result = testdir.runpytest('--nomigrations', '--tb=short', '-v')
451+
assert result.ret == 0
411452
result.stdout.fnmatch_lines(['*test_inner_migrations*PASSED*'])
412453

413454
@pytest.mark.skipif(get_django_version() < (1, 7),
@@ -453,4 +494,5 @@ class Migration(migrations.Migration):
453494
]
454495
""", 'migrations/0001_initial.py')
455496
result = testdir.runpytest('--tb=short', '-v', '-s')
497+
assert result.ret == 0
456498
result.stdout.fnmatch_lines(['*mark_migrations_run*'])

tests/test_django_configurations.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def test_settings():
4646
""")
4747
result = testdir.runpytest()
4848
result.stdout.fnmatch_lines(['*1 passed*'])
49+
assert result.ret == 0
4950

5051

5152
def test_dc_ini(testdir, monkeypatch):
@@ -69,6 +70,7 @@ def test_ds():
6970
""")
7071
result = testdir.runpytest()
7172
result.stdout.fnmatch_lines(['*1 passed*'])
73+
assert result.ret == 0
7274

7375

7476
def test_dc_option(testdir, monkeypatch):
@@ -92,3 +94,4 @@ def test_ds():
9294
""")
9395
result = testdir.runpytest('--ds=tpkg.settings_opt', '--dc=MySettings')
9496
result.stdout.fnmatch_lines(['*1 passed*'])
97+
assert result.ret == 0

tests/test_django_settings_module.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test_settings():
3232
""")
3333
result = testdir.runpytest()
3434
result.stdout.fnmatch_lines(['*1 passed*'])
35+
assert result.ret == 0
3536

3637

3738
def test_ds_ini(testdir, monkeypatch):
@@ -51,6 +52,7 @@ def test_ds():
5152
""")
5253
result = testdir.runpytest()
5354
result.stdout.fnmatch_lines(['*1 passed*'])
55+
assert result.ret == 0
5456

5557

5658
def test_ds_option(testdir, monkeypatch):
@@ -70,6 +72,7 @@ def test_ds():
7072
""")
7173
result = testdir.runpytest('--ds=tpkg.settings_opt')
7274
result.stdout.fnmatch_lines(['*1 passed*'])
75+
assert result.ret == 0
7376

7477

7578
def test_ds_non_existent(testdir, monkeypatch):
@@ -81,6 +84,7 @@ def test_ds_non_existent(testdir, monkeypatch):
8184
testdir.makepyfile('def test_ds(): pass')
8285
result = testdir.runpytest()
8386
result.stderr.fnmatch_lines(["*ImportError:*DOES_NOT_EXIST*"])
87+
assert result.ret != 0
8488

8589

8690
def test_ds_after_user_conftest(testdir, monkeypatch):
@@ -94,6 +98,7 @@ def test_ds_after_user_conftest(testdir, monkeypatch):
9498
# testdir.makeconftest("import sys; print(sys.path)")
9599
result = testdir.runpytest('-v')
96100
result.stdout.fnmatch_lines(['*1 passed*'])
101+
assert result.ret == 0
97102

98103

99104
def test_ds_in_pytest_configure(testdir, monkeypatch):
@@ -211,6 +216,7 @@ def test_settings():
211216
""")
212217
result = testdir.runpytest()
213218
result.stdout.fnmatch_lines(['*1 passed*'])
219+
assert result.ret == 0
214220

215221

216222
def test_debug_false(testdir, monkeypatch):
@@ -282,6 +288,7 @@ def test_anything():
282288
result.stdout.fnmatch_lines(['*IMPORT: populating=True,ready=False*'])
283289
result.stdout.fnmatch_lines(['*READY(): populating=True*'])
284290
result.stdout.fnmatch_lines(['*TEST: populating=False,ready=True*'])
291+
assert result.ret == 0
285292

286293

287294
def test_no_ds_but_django_imported(testdir, monkeypatch):

tests/test_fixtures.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def test_a(self, live_server, settings):
189189
""")
190190
result = django_testdir.runpytest('--tb=short', '-v')
191191
result.stdout.fnmatch_lines(['*test_a*PASSED*'])
192+
assert result.ret == 0
192193

193194
@pytest.mark.skipif(get_django_version() < (1, 7),
194195
reason="Django >= 1.7 required")
@@ -305,3 +306,4 @@ class Migration(migrations.Migration):
305306

306307
result = django_testdir.runpytest('-s')
307308
result.stdout.fnmatch_lines(['*1 passed*'])
309+
assert result.ret == 0

tests/test_manage_py_scan.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def test_django_project_found_invalid_settings(django_testdir, monkeypatch):
2929
monkeypatch.setenv('DJANGO_SETTINGS_MODULE', 'DOES_NOT_EXIST')
3030

3131
result = django_testdir.runpytest('django_project_root')
32+
assert result.ret != 0
33+
3234
result.stderr.fnmatch_lines(['*ImportError:*DOES_NOT_EXIST*'])
3335
result.stderr.fnmatch_lines(['*pytest-django found a Django project*'])
3436

@@ -43,6 +45,7 @@ def test_django_project_scan_disabled_invalid_settings(django_testdir,
4345
''')
4446

4547
result = django_testdir.runpytest('django_project_root')
48+
assert result.ret != 0
4649

4750
result.stderr.fnmatch_lines(['*ImportError*DOES_NOT_EXIST*'])
4851
result.stderr.fnmatch_lines(['*pytest-django did not search for '

0 commit comments

Comments
 (0)