... すべての標準の Python のユニットテスト機能が利用可能なまま、以下の各セクションで説明するような便利な追加機能を追加できます。 SimpleTestCase class SimpleTestCase [ソース] 以下の機能を追加する、 unittest.TestCase のサブクラスです。 便利なアサーションには以下のよう ... c_client attributes. データベースクエリを作る手薄との場合、サブクラス TransactionTestCase や TestCase を使用してください。 SimpleTestCase. databases SimpleTestCase はデフォルトでデータベースクエリを許可しません。各 SimpleTestCase テストはトランザクション内で実 ... 題が心配でない場合は、テストクラスの databases クラス属性を '__all__' に設定することで、この振る舞いを無効化できます。 警告 SimpleTestCase とそのサブクラス (例: TestCase など) は、クラス横断的な初期化を実現するために setUpClass() と tearDownClass() に依存してい ... ... クラス) ASin (django.db.models.functions のクラス) AsKML (django.contrib.gis.db.models.functions のクラス) assertContains() (SimpleTestCase のメソッド) assertFieldOutput() (SimpleTestCase のメソッド) assertFormError() (SimpleTestCase のメソッド) assertFormSetErr ... or() (SimpleTestCase のメソッド) assertHTMLEqual() (SimpleTestCase のメソッド) assertHTMLNotEqual() (SimpleTestCase のメソッド) assertInHTML() ... (SimpleTestCase のメソッド) assertJSONEqual() (SimpleTestCase のメソッド) assertJSONNotEqual() (SimpleTestCase のメソッド) assertMessages( ... ... jango.core.management import call_command from django.core.management.base import SystemCheckError from django.test import SimpleTestCase , modify_settings , override_settings class SystemCheckIntegrationTest ( SimpleTestCase ): @override_settings ( SITE_ID = ... あることをアサートできます: from io import StringIO from django.core.management import call_command from django.test import SimpleTestCase , override_settings class EnableAnalyticsDeploymentCheckTest ( SimpleTestCase ): @override_settings ( ENABLE_ANALYTICS = N ... ... emporary Apps instance. To do this, use the isolate_apps() decorator: from django.db import models from django.test import SimpleTestCase from django.test.utils import isolate_apps class TestModelDefinition ( SimpleTestCase ): @isolate_apps ( "app_label" ) def ... the set of targeted app_label as arguments: tests/app_label/tests.py from django.db import models from django.test import SimpleTestCase from django.test.utils import isolate_apps class TestModelDefinition ( SimpleTestCase ): @isolate_apps ( "app_label" , "ot ... ... ... rib.postgres.fields.CIText ミックスインは削除されます。 BaseGeometryWidget の map_width と map_height 属性は削除されます。 SimpleTestCase.assertFormsetError() メソッドは削除されます。 TransactionTestCase.assertQuerysetEqual() メソッドは削除されます。 JSONField ... ます。 django.contrib.postgres.constraints.ExclusionConstraint の opclasses 引数は削除されます。 ドキュメント化されていない SimpleTestCase.assertFormError() および assertFormsetError() への errors=None という引数の渡し方は削除されます。 django.contrib.sessions. ... ト経由のログアウトのサポートが削除されます。 datetime.timezone.utc への django.utils.timezone.utc エイリアスは削除されます。 SimpleTestCase.assertFormError() および assertFormsetError() にレスポンスオブジェクトとフォーム/フォームセット名を渡すことはできなくなりま ... ... = { "action" : "delete" }) await self . async_client . post ( "/items/1" , query_params = { "action" : "delete" }) 新しい SimpleTestCase.assertNotInHTML() アサーションにより、指定されたHTMLヘイスタック内に特定のHTMLフラグメントが含まれていないことをテストでき ... るようになりました。 テストの独立性を確保するため、 SimpleTestCase 内でスレッド内のデータベース接続が許可されなくなりました。 バリデータ 新しい DomainNameValidator は、国際化ドメイン名を含む ... > 要素を含むようになりました。 JavaScript ファイル collapse.js は、Django admin サイトでは不要になったので削除されました。 SimpleTestCase.assertURLEqual() と assertInHTML() は ": " を msg_prefix に追加します。これにより、他のアサーションの振る舞いと一致するよう ... ... rences=True to serializers.deserialize() . Additionally, loaddata handles forward references automatically. テスト The new SimpleTestCase.assertURLEqual() assertion checks for a given URL, ignoring the ordering of the query string. assertRedirects() uses the n ... first positional argument, if it accepts it. Support for overrides that don't accept it will be removed in Django 3.1. The SimpleTestCase.allow_database_queries , TransactionTestCase.multi_db , and TestCase.multi_db attributes are deprecated in favor of Simple ... ... うファイルを新たに作ります。以下のコードを追加してください。 from django.shortcuts import make_toast from django.test import SimpleTestCase class MakeToastTests ( SimpleTestCase ): def test_make_toast ( self ): self . assertEqual ( make_toast (), "toast" ) このテ ... +++ b/tests/shortcuts/test_make_toast.py @@ -0,0 +1,7 @@ +from django.shortcuts import make_toast +from django.test import SimpleTestCase + + +class MakeToastTests(SimpleTestCase): + def test_make_toast(self): + self.assertEqual(make_toast(), 'toast') 変更内容 ... ... バグ修正 Prevented the loss of null / not null column properties during field renaming of MySQL databases ( #24817 ). Fixed SimpleTestCase.assertRaisesMessage() on Python 2.7.10 ( #24903 ). ... 2026年10月08日