Skip to content

Commit db37f64

Browse files
authored
django_db_setup: warn instead of crash with teardown errors (#726)
Previously it would cause pytest to crash, and this is just something to warn about anyway. Ref: django/channels#1091 (comment)
1 parent 787bbec commit db37f64

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pytest_django/fixtures.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,14 @@ def django_db_setup(
110110

111111
def teardown_database():
112112
with django_db_blocker.unblock():
113-
teardown_databases(db_cfg, verbosity=request.config.option.verbose)
113+
try:
114+
teardown_databases(db_cfg, verbosity=request.config.option.verbose)
115+
except Exception as exc:
116+
request.node.warn(
117+
pytest.PytestWarning(
118+
"Error when trying to teardown test databases: %r" % exc
119+
)
120+
)
114121

115122
if not django_db_keepdb:
116123
request.addfinalizer(teardown_database)

0 commit comments

Comments
 (0)