Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
1181b8a4
Kaydet (Commit)
1181b8a4
authored
Haz 06, 2014
tarafından
Aymeric Augustin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pull request #2764 from gchp/ticket-20550
Fixed #20550 -- Added keepdb argument to destroy_test_db
üst
daaeb841
72f055e5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
9 deletions
+25
-9
AUTHORS
AUTHORS
+1
-0
creation.py
django/db/backends/creation.py
+10
-4
runner.py
django/test/runner.py
+2
-2
advanced.txt
docs/topics/testing/advanced.txt
+11
-2
tests.py
tests/test_runner/tests.py
+1
-1
No files found.
AUTHORS
Dosyayı görüntüle @
1181b8a4
...
...
@@ -154,6 +154,7 @@ answer newbie questions, and generally made Django that much better:
Antonio Cavedoni <http://cavedoni.com/>
cedric@terramater.net
Chris Chamberlin <dja@cdc.msbx.net>
Greg Chapple <gregchapple1@gmail.com>
Amit Chakradeo <http://amit.chakradeo.net/>
ChaosKCW
Kowito Charoenratchatabhan <kowito@felspar.com>
...
...
django/db/backends/creation.py
Dosyayı görüntüle @
1181b8a4
...
...
@@ -449,7 +449,7 @@ class BaseDatabaseCreation(object):
return
test_database_name
def
destroy_test_db
(
self
,
old_database_name
,
verbosity
=
1
):
def
destroy_test_db
(
self
,
old_database_name
,
verbosity
=
1
,
keepdb
=
False
):
"""
Destroy a test database, prompting the user for confirmation if the
database already exists.
...
...
@@ -458,12 +458,18 @@ class BaseDatabaseCreation(object):
test_database_name
=
self
.
connection
.
settings_dict
[
'NAME'
]
if
verbosity
>=
1
:
test_db_repr
=
''
action
=
'Destroying'
if
verbosity
>=
2
:
test_db_repr
=
" ('
%
s')"
%
test_database_name
print
(
"Destroying test database for alias '
%
s'
%
s..."
%
(
self
.
connection
.
alias
,
test_db_repr
))
if
keepdb
:
action
=
'Preserving'
print
(
"
%
s test database for alias '
%
s'
%
s..."
%
(
action
,
self
.
connection
.
alias
,
test_db_repr
))
self
.
_destroy_test_db
(
test_database_name
,
verbosity
)
# if we want to preserve the database
# skip the actual destroying piece.
if
not
keepdb
:
self
.
_destroy_test_db
(
test_database_name
,
verbosity
)
def
_destroy_test_db
(
self
,
test_database_name
,
verbosity
):
"""
...
...
django/test/runner.py
Dosyayı görüntüle @
1181b8a4
...
...
@@ -124,8 +124,8 @@ class DiscoverRunner(object):
"""
old_names
,
mirrors
=
old_config
for
connection
,
old_name
,
destroy
in
old_names
:
if
destroy
and
not
self
.
keepdb
:
connection
.
creation
.
destroy_test_db
(
old_name
,
self
.
verbosity
)
if
destroy
:
connection
.
creation
.
destroy_test_db
(
old_name
,
self
.
verbosity
,
self
.
keepdb
)
def
teardown_test_environment
(
self
,
**
kwargs
):
unittest
.
removeHandler
()
...
...
docs/topics/testing/advanced.txt
Dosyayı görüntüle @
1181b8a4
...
...
@@ -485,7 +485,7 @@ django.db.connection.creation
The creation module of the database backend also provides some utilities that
can be useful during testing.
.. function:: create_test_db([verbosity=1, autoclobber=False])
.. function:: create_test_db([verbosity=1, autoclobber=False
, keepdb=False
])
Creates a new test database and runs ``migrate`` against it.
...
...
@@ -501,13 +501,19 @@ can be useful during testing.
* If autoclobber is ``True``, the database will be destroyed
without consulting the user.
``keepdb`` determines if the test run should use an existing
database, or create a new one. If ``True``, the existing
database will be used, or created if not present. If ``False``,
a new database will be created, prompting the user to remove
the existing one, if present.
Returns the name of the test database that it created.
``create_test_db()`` has the side effect of modifying the value of
:setting:`NAME` in :setting:`DATABASES` to match the name of the test
database.
.. function:: destroy_test_db(old_database_name, [verbosity=1])
.. function:: destroy_test_db(old_database_name, [verbosity=1
, keepdb=False
])
Destroys the database whose name is the value of :setting:`NAME` in
:setting:`DATABASES`, and sets :setting:`NAME` to the value of
...
...
@@ -516,6 +522,9 @@ can be useful during testing.
The ``verbosity`` argument has the same behavior as for
:class:`~django.test.runner.DiscoverRunner`.
If the ``keepdb`` argument is ``True``, then the connection to the
database will be closed, but the database will not be destroyed.
.. _topics-testing-code-coverage:
Integration with coverage.py
...
...
tests/test_runner/tests.py
Dosyayı görüntüle @
1181b8a4
...
...
@@ -309,7 +309,7 @@ class AliasedDatabaseTeardownTest(unittest.TestCase):
old_create_test_db
=
DatabaseCreation
.
create_test_db
try
:
destroyed_names
=
[]
DatabaseCreation
.
destroy_test_db
=
lambda
self
,
old_database_name
,
verbosity
=
1
:
destroyed_names
.
append
(
old_database_name
)
DatabaseCreation
.
destroy_test_db
=
lambda
self
,
old_database_name
,
verbosity
=
1
,
keepdb
=
False
:
destroyed_names
.
append
(
old_database_name
)
DatabaseCreation
.
create_test_db
=
lambda
self
,
verbosity
=
1
,
autoclobber
=
False
,
keepdb
=
False
:
self
.
_get_test_db_name
()
db
.
connections
=
db
.
ConnectionHandler
({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment