Code

Opened 21 months ago

Closed 18 months ago

Last modified 18 months ago

#19192 closed Bug (fixed)

DjangoTestSuiteRunner cannot run with dummy database backend

Reported by: claudep Owned by: Architekt
Component: Testing framework Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

(from https://code.djangoproject.com/ticket/18575#comment:9)

To support Django app testing without requiring a database, one can omit the DATABASES setting so as the default dummy backend is configured. Unfortunately, DjangoTestSuiteRunner does not support this configuration, as it raises ImproperlyConfigured at the time the connection.creation.create_test_db is called.

Attachments (0)

Change History (7)

comment:1 Changed 21 months ago by Architekt

  • Has patch set
  • Owner changed from nobody to Architekt

Here is patch: https://github.com/django/django/pull/475

Patch skips calling create_test_db and destory_test_db for dummy database backend.

Testing without database (with dummy database backend) works only for SimpleTestCase.

(I added myself into authors because It's my 4th small patch and I did also triaging of few tickets.)

comment:2 Changed 21 months ago by Architekt

I made a mistake in patch...

comment:3 Changed 21 months ago by Architekt

Patch and pull request has been updated, ready for review.

comment:4 Changed 19 months ago by charettes

What about providing a dummy database creation class that ignores create_test_db and destroy_test_db instead?

diff --git a/django/db/backends/dummy/base.py b/django/db/backends/dummy/base.py
index 12a940d..b648aae 100644
--- a/django/db/backends/dummy/base.py
+++ b/django/db/backends/dummy/base.py
@@ -31,6 +31,10 @@ class DatabaseOperations(BaseDatabaseOperations):
 class DatabaseClient(BaseDatabaseClient):
     runshell = complain
 
+class DatabaseCreation(BaseDatabaseCreation):
+    create_test_db = ignore
+    destroy_test_db = ignore
+
 class DatabaseIntrospection(BaseDatabaseIntrospection):
     get_table_list = complain
     get_table_description = complain
@@ -64,6 +68,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
         self.features = BaseDatabaseFeatures(self)
         self.ops = DatabaseOperations(self)
         self.client = DatabaseClient(self)
-        self.creation = BaseDatabaseCreation(self)
+        self.creation = DatabaseCreation(self)
         self.introspection = DatabaseIntrospection(self)
         self.validation = BaseDatabaseValidation(self)

This also allows SimpleTestCase to work just fine.

comment:5 Changed 18 months ago by claudep

Yes, Simon's solution is a lot more elegant/pythonic. I will add a test and commit.

comment:6 Changed 18 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

In b740da3504ea3b9c841f5a9eb14191a0b5410565:

Fixed #19192 -- Allowed running tests with dummy db backend

Thanks Simon Charette for the initial patch, and Jan Bednařík for
his work on the ticket.

comment:7 Changed 18 months ago by Claude Paroz <claude@…>

In 96301d21bb2ec7c5e06e3cea54fa2cdcd25a464d:

[1.5.x] Fixed #19192 -- Allowed running tests with dummy db backend

Thanks Simon Charette for the initial patch, and Jan Bednařík for
his work on the ticket.
Backport of b740da3504 from master.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.