Skip to content

Commit 4cad31f

Browse files
committed
tests: add assertions for ret to runpytest calls
1 parent 4f9b581 commit 4cad31f

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

tests/test_db_setup.py

Lines changed: 16 additions & 0 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

@@ -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*'])
@@ -315,6 +326,7 @@ def test_inner_south():
315326
testdir.create_initial_south_migration()
316327

317328
result = testdir.runpytest('--tb=short', '-v', '-s')
329+
assert result.ret == 0
318330
result.stdout.fnmatch_lines_random([
319331
"tpkg/test_the_test.py::test_inner_south*",
320332
"*mark_south_migration_forwards*",
@@ -345,6 +357,7 @@ def test_inner_south():
345357
ensure=True)
346358

347359
result = testdir.runpytest('--tb=short', '-v', '-s')
360+
assert result.ret == 0
348361
result.stdout.fnmatch_lines_random([
349362
"tpkg/test_the_test.py::test_inner_south*",
350363
"*PASSED*",
@@ -380,6 +393,7 @@ def test_inner_south():
380393
python_files=*.py""", 'pytest.ini')
381394

382395
result = testdir.runpytest('--tb=short', '-v', '-s', '-c', pytest_ini)
396+
assert result.ret == 0
383397
result.stdout.fnmatch_lines_random([
384398
"tpkg/test.py::test_inner_south*",
385399
"*mark_south_migration_forwards*",
@@ -408,6 +422,7 @@ def test_inner_migrations():
408422
ensure=True)
409423

410424
result = testdir.runpytest('--nomigrations', '--tb=short', '-v')
425+
assert result.ret == 0
411426
result.stdout.fnmatch_lines(['*test_inner_migrations*PASSED*'])
412427

413428
@pytest.mark.skipif(get_django_version() < (1, 7),
@@ -453,4 +468,5 @@ class Migration(migrations.Migration):
453468
]
454469
""", 'migrations/0001_initial.py')
455470
result = testdir.runpytest('--tb=short', '-v', '-s')
471+
assert result.ret == 0
456472
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)