{"title":"Advanced testing topics","version":"4.2","locale":"pt-br","docname":"topics/testing/advanced","url":"/pt-br/4.2/topics/testing/advanced/","canonical":"https://djangodocs.dev/pt-br/4.2/topics/testing/advanced/","summary":"The RequestFactory shares the same API as the test client. However, instead of behaving like a browser, the RequestFactory provides a way to generate a…","html":"<h1>Advanced testing topics<a class=\"heading-anchor\" href=\"#advanced-testing-topics\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h1>\n<section id=\"the-request-factory\">\n<h2>The request factory<a class=\"heading-anchor\" href=\"#the-request-factory\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.test.RequestFactory\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">RequestFactory</span><a class=\"heading-anchor\" href=\"#django.test.RequestFactory\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>The <a class=\"reference internal\" href=\"#django.test.RequestFactory\" title=\"django.test.RequestFactory\"><code class=\"xref py py-class docutils literal notranslate\">RequestFactory</code></a> shares the same API as\nthe test client. However, instead of behaving like a browser, the\nRequestFactory provides a way to generate a request instance that can\nbe used as the first argument to any view. This means you can test a\nview function the same way as you would test any other function – as\na black box, with exactly known inputs, testing for specific outputs.</p>\n<p>The API for the <a class=\"reference internal\" href=\"#django.test.RequestFactory\" title=\"django.test.RequestFactory\"><code class=\"xref py py-class docutils literal notranslate\">RequestFactory</code></a> is a slightly\nrestricted subset of the test client API:</p>\n<ul class=\"simple\">\n<li><p>It only has access to the HTTP methods <a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/tools/#django.test.Client.get\" title=\"django.test.Client.get\"><code class=\"xref py py-meth docutils literal notranslate\">get()</code></a>,\n<a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/tools/#django.test.Client.post\" title=\"django.test.Client.post\"><code class=\"xref py py-meth docutils literal notranslate\">post()</code></a>, <a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/tools/#django.test.Client.put\" title=\"django.test.Client.put\"><code class=\"xref py py-meth docutils literal notranslate\">put()</code></a>,\n<a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/tools/#django.test.Client.delete\" title=\"django.test.Client.delete\"><code class=\"xref py py-meth docutils literal notranslate\">delete()</code></a>, <a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/tools/#django.test.Client.head\" title=\"django.test.Client.head\"><code class=\"xref py py-meth docutils literal notranslate\">head()</code></a>,\n<a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/tools/#django.test.Client.options\" title=\"django.test.Client.options\"><code class=\"xref py py-meth docutils literal notranslate\">options()</code></a>, and <a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/tools/#django.test.Client.trace\" title=\"django.test.Client.trace\"><code class=\"xref py py-meth docutils literal notranslate\">trace()</code></a>.</p></li>\n<li><p>These methods accept all the same arguments <em>except</em> for\n<code class=\"docutils literal notranslate\">follow</code>. Since this is just a factory for producing\nrequests, it’s up to you to handle the response.</p></li>\n<li><p>It does not support middleware. Session and authentication\nattributes must be supplied by the test itself if required\nfor the view to function properly.</p></li>\n</ul>\n<aside class=\"version-note version-changed\" data-version=\"4.2\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 4.2</p><p>The <code class=\"docutils literal notranslate\">headers</code> parameter was added.</p>\n</aside>\n<section id=\"example\">\n<h3>Exemplo<a class=\"heading-anchor\" href=\"#example\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The following is a unit test using the request factory:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.contrib.auth.models</span> <span class=\"kn\">import</span> AnonymousUser<span class=\"p\">,</span> User\n<span class=\"kn\">from</span> <span class=\"nn\">django.test</span> <span class=\"kn\">import</span> RequestFactory<span class=\"p\">,</span> TestCase\n\n<span class=\"kn\">from</span> <span class=\"nn\">.views</span> <span class=\"kn\">import</span> MyView<span class=\"p\">,</span> my_view\n\n\n<span class=\"k\">class</span> <span class=\"nc\">SimpleTest</span><span class=\"p\">(</span>TestCase<span class=\"p\">):</span>\n    <span class=\"k\">def</span> <span class=\"nf\">setUp</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"c1\"># Every test needs access to the request factory.</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>factory <span class=\"o\">=</span> RequestFactory<span class=\"p\">()</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>user <span class=\"o\">=</span> User<span class=\"o\">.</span>objects<span class=\"o\">.</span>create_user<span class=\"p\">(</span>\n            username<span class=\"o\">=</span><span class=\"s2\">&quot;jacob&quot;</span><span class=\"p\">,</span> email<span class=\"o\">=</span><span class=\"s2\">&quot;jacob@…&quot;</span><span class=\"p\">,</span> password<span class=\"o\">=</span><span class=\"s2\">&quot;top_secret&quot;</span>\n        <span class=\"p\">)</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">test_details</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"c1\"># Create an instance of a GET request.</span>\n        request <span class=\"o\">=</span> <span class=\"bp\">self</span><span class=\"o\">.</span>factory<span class=\"o\">.</span>get<span class=\"p\">(</span><span class=\"s2\">&quot;/customer/details&quot;</span><span class=\"p\">)</span>\n\n        <span class=\"c1\"># Recall that middleware are not supported. You can simulate a</span>\n        <span class=\"c1\"># logged-in user by setting request.user manually.</span>\n        request<span class=\"o\">.</span>user <span class=\"o\">=</span> <span class=\"bp\">self</span><span class=\"o\">.</span>user\n\n        <span class=\"c1\"># Or you can simulate an anonymous user by setting request.user to</span>\n        <span class=\"c1\"># an AnonymousUser instance.</span>\n        request<span class=\"o\">.</span>user <span class=\"o\">=</span> AnonymousUser<span class=\"p\">()</span>\n\n        <span class=\"c1\"># Test my_view() as if it were deployed at /customer/details</span>\n        response <span class=\"o\">=</span> my_view<span class=\"p\">(</span>request<span class=\"p\">)</span>\n        <span class=\"c1\"># Use this syntax for class-based views.</span>\n        response <span class=\"o\">=</span> MyView<span class=\"o\">.</span>as_view<span class=\"p\">()(</span>request<span class=\"p\">)</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>assertEqual<span class=\"p\">(</span>response<span class=\"o\">.</span>status_code<span class=\"p\">,</span> <span class=\"mi\">200</span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n<section id=\"asyncrequestfactory\">\n<h3>AsyncRequestFactory<a class=\"heading-anchor\" href=\"#asyncrequestfactory\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.test.AsyncRequestFactory\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">AsyncRequestFactory</span><a class=\"heading-anchor\" href=\"#django.test.AsyncRequestFactory\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><code class=\"docutils literal notranslate\">RequestFactory</code> creates WSGI-like requests. If you want to create ASGI-like\nrequests, including having a correct ASGI <code class=\"docutils literal notranslate\">scope</code>, you can instead use\n<code class=\"docutils literal notranslate\">django.test.AsyncRequestFactory</code>.</p>\n<p>This class is directly API-compatible with <code class=\"docutils literal notranslate\">RequestFactory</code>, with the only\ndifference being that it returns <code class=\"docutils literal notranslate\">ASGIRequest</code> instances rather than\n<code class=\"docutils literal notranslate\">WSGIRequest</code> instances. All of its methods are still synchronous callables.</p>\n<p>Arbitrary keyword arguments in <code class=\"docutils literal notranslate\">defaults</code> are added directly into the ASGI\nscope.</p>\n<aside class=\"version-note version-changed\" data-version=\"4.2\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 4.2</p><p>The <code class=\"docutils literal notranslate\">headers</code> parameter was added.</p>\n</aside>\n</section>\n</section>\n<section id=\"testing-class-based-views\">\n<h2>Testing class-based views<a class=\"heading-anchor\" href=\"#testing-class-based-views\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>In order to test class-based views outside of the request/response cycle you\nmust ensure that they are configured correctly, by calling\n<a class=\"reference internal\" href=\"/pt-br/4.2/ref/class-based-views/base/#django.views.generic.base.View.setup\" title=\"django.views.generic.base.View.setup\"><code class=\"xref py py-meth docutils literal notranslate\">setup()</code></a> after instantiation.</p>\n<p>For example, assuming the following class-based view:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\">views.py</code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.views.generic</span> <span class=\"kn\">import</span> TemplateView\n\n\n<span class=\"k\">class</span> <span class=\"nc\">HomeView</span><span class=\"p\">(</span>TemplateView<span class=\"p\">):</span>\n    template_name <span class=\"o\">=</span> <span class=\"s2\">&quot;myapp/home.html&quot;</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">get_context_data</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"o\">**</span>kwargs<span class=\"p\">):</span>\n        kwargs<span class=\"p\">[</span><span class=\"s2\">&quot;environment&quot;</span><span class=\"p\">]</span> <span class=\"o\">=</span> <span class=\"s2\">&quot;Production&quot;</span>\n        <span class=\"k\">return</span> <span class=\"nb\">super</span><span class=\"p\">()</span><span class=\"o\">.</span>get_context_data<span class=\"p\">(</span><span class=\"o\">**</span>kwargs<span class=\"p\">)</span>\n</code></pre></figure>\n<p>You may directly test the <code class=\"docutils literal notranslate\">get_context_data()</code> method by first instantiating\nthe view, then passing a <code class=\"docutils literal notranslate\">request</code> to <code class=\"docutils literal notranslate\">setup()</code>, before proceeding with\nyour test’s code:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\">tests.py</code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.test</span> <span class=\"kn\">import</span> RequestFactory<span class=\"p\">,</span> TestCase\n<span class=\"kn\">from</span> <span class=\"nn\">.views</span> <span class=\"kn\">import</span> HomeView\n\n\n<span class=\"k\">class</span> <span class=\"nc\">HomePageTest</span><span class=\"p\">(</span>TestCase<span class=\"p\">):</span>\n    <span class=\"k\">def</span> <span class=\"nf\">test_environment_set_in_context</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        request <span class=\"o\">=</span> RequestFactory<span class=\"p\">()</span><span class=\"o\">.</span>get<span class=\"p\">(</span><span class=\"s2\">&quot;/&quot;</span><span class=\"p\">)</span>\n        view <span class=\"o\">=</span> HomeView<span class=\"p\">()</span>\n        view<span class=\"o\">.</span>setup<span class=\"p\">(</span>request<span class=\"p\">)</span>\n\n        context <span class=\"o\">=</span> view<span class=\"o\">.</span>get_context_data<span class=\"p\">()</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>assertIn<span class=\"p\">(</span><span class=\"s2\">&quot;environment&quot;</span><span class=\"p\">,</span> context<span class=\"p\">)</span>\n</code></pre></figure>\n</section>\n<section id=\"tests-and-multiple-host-names\">\n<span id=\"topics-testing-advanced-multiple-hosts\"></span><h2>Tests and multiple host names<a class=\"heading-anchor\" href=\"#tests-and-multiple-host-names\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-ALLOWED_HOSTS\"><code class=\"xref std std-setting docutils literal notranslate\">ALLOWED_HOSTS</code></a> setting is validated when running tests. This\nallows the test client to differentiate between internal and external URLs.</p>\n<p>Projects that support multitenancy or otherwise alter business logic based on\nthe request’s host and use custom host names in tests must include those hosts\nin <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-ALLOWED_HOSTS\"><code class=\"xref std std-setting docutils literal notranslate\">ALLOWED_HOSTS</code></a>.</p>\n<p>The first option to do so is to add the hosts to your settings file. For\nexample, the test suite for docs.djangoproject.com includes the following:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.test</span> <span class=\"kn\">import</span> TestCase\n\n\n<span class=\"k\">class</span> <span class=\"nc\">SearchFormTestCase</span><span class=\"p\">(</span>TestCase<span class=\"p\">):</span>\n    <span class=\"k\">def</span> <span class=\"nf\">test_empty_get</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        response <span class=\"o\">=</span> <span class=\"bp\">self</span><span class=\"o\">.</span>client<span class=\"o\">.</span>get<span class=\"p\">(</span>\n            <span class=\"s2\">&quot;/en/dev/search/&quot;</span><span class=\"p\">,</span>\n            headers<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s2\">&quot;host&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;docs.djangoproject.dev:8000&quot;</span><span class=\"p\">},</span>\n        <span class=\"p\">)</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>assertEqual<span class=\"p\">(</span>response<span class=\"o\">.</span>status_code<span class=\"p\">,</span> <span class=\"mi\">200</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>and the settings file includes a list of the domains supported by the project:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>ALLOWED_HOSTS <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"s2\">&quot;www.djangoproject.dev&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;docs.djangoproject.dev&quot;</span><span class=\"p\">,</span> <span class=\"o\">...</span><span class=\"p\">]</span>\n</code></pre></div>\n<p>Another option is to add the required hosts to <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-ALLOWED_HOSTS\"><code class=\"xref std std-setting docutils literal notranslate\">ALLOWED_HOSTS</code></a> using\n<a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/tools/#django.test.override_settings\" title=\"django.test.override_settings\"><code class=\"xref py py-meth docutils literal notranslate\">override_settings()</code></a> or\n<a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/tools/#django.test.SimpleTestCase.modify_settings\" title=\"django.test.SimpleTestCase.modify_settings\"><code class=\"xref py py-attr docutils literal notranslate\">modify_settings()</code></a>. This option may be\npreferable in standalone apps that can’t package their own settings file or\nfor projects where the list of domains is not static (e.g., subdomains for\nmultitenancy). For example, you could write a test for the domain\n<code class=\"docutils literal notranslate\">http://otherserver/</code> as follows:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.test</span> <span class=\"kn\">import</span> TestCase<span class=\"p\">,</span> override_settings\n\n\n<span class=\"k\">class</span> <span class=\"nc\">MultiDomainTestCase</span><span class=\"p\">(</span>TestCase<span class=\"p\">):</span>\n    <span class=\"nd\">@override_settings</span><span class=\"p\">(</span>ALLOWED_HOSTS<span class=\"o\">=</span><span class=\"p\">[</span><span class=\"s2\">&quot;otherserver&quot;</span><span class=\"p\">])</span>\n    <span class=\"k\">def</span> <span class=\"nf\">test_other_domain</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        response <span class=\"o\">=</span> <span class=\"bp\">self</span><span class=\"o\">.</span>client<span class=\"o\">.</span>get<span class=\"p\">(</span><span class=\"s2\">&quot;http://otherserver/foo/bar/&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Disabling <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-ALLOWED_HOSTS\"><code class=\"xref std std-setting docutils literal notranslate\">ALLOWED_HOSTS</code></a> checking (<code class=\"docutils literal notranslate\">ALLOWED_HOSTS = ['*']</code>) when\nrunning tests prevents the test client from raising a helpful error message if\nyou follow a redirect to an external URL.</p>\n</section>\n<section id=\"tests-and-multiple-databases\">\n<span id=\"topics-testing-advanced-multidb\"></span><h2>Tests and multiple databases<a class=\"heading-anchor\" href=\"#tests-and-multiple-databases\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"testing-primary-replica-configurations\">\n<span id=\"topics-testing-primaryreplica\"></span><h3>Testing primary/replica configurations<a class=\"heading-anchor\" href=\"#testing-primary-replica-configurations\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you’re testing a multiple database configuration with primary/replica\n(referred to as master/slave by some databases) replication, this strategy of\ncreating test databases poses a problem.\nWhen the test databases are created, there won’t be any replication,\nand as a result, data created on the primary won’t be seen on the\nreplica.</p>\n<p>To compensate for this, Django allows you to define that a database is\na <em>test mirror</em>. Consider the following (simplified) example database\nconfiguration:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>DATABASES <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.db.backends.mysql&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;NAME&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;myproject&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;HOST&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;dbprimary&quot;</span><span class=\"p\">,</span>\n        <span class=\"c1\"># ... plus some other settings</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;replica&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;ENGINE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.db.backends.mysql&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;NAME&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;myproject&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;HOST&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;dbreplica&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;TEST&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;MIRROR&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n        <span class=\"c1\"># ... plus some other settings</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>In this setup, we have two database servers: <code class=\"docutils literal notranslate\">dbprimary</code>, described\nby the database alias <code class=\"docutils literal notranslate\">default</code>, and <code class=\"docutils literal notranslate\">dbreplica</code> described by the\nalias <code class=\"docutils literal notranslate\">replica</code>. As you might expect, <code class=\"docutils literal notranslate\">dbreplica</code> has been configured\nby the database administrator as a read replica of <code class=\"docutils literal notranslate\">dbprimary</code>, so in\nnormal activity, any write to <code class=\"docutils literal notranslate\">default</code> will appear on <code class=\"docutils literal notranslate\">replica</code>.</p>\n<p>If Django created two independent test databases, this would break any\ntests that expected replication to occur. However, the <code class=\"docutils literal notranslate\">replica</code>\ndatabase has been configured as a test mirror (using the\n<a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-TEST_MIRROR\"><code class=\"xref std std-setting docutils literal notranslate\">MIRROR</code></a> test setting), indicating that under\ntesting, <code class=\"docutils literal notranslate\">replica</code> should be treated as a mirror of <code class=\"docutils literal notranslate\">default</code>.</p>\n<p>When the test environment is configured, a test version of <code class=\"docutils literal notranslate\">replica</code>\nwill <em>not</em> be created. Instead the connection to <code class=\"docutils literal notranslate\">replica</code>\nwill be redirected to point at <code class=\"docutils literal notranslate\">default</code>. As a result, writes to\n<code class=\"docutils literal notranslate\">default</code> will appear on <code class=\"docutils literal notranslate\">replica</code> – but because they are actually\nthe same database, not because there is data replication between the\ntwo databases. As this depends on transactions, the tests must use\n<a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/tools/#django.test.TransactionTestCase\" title=\"django.test.TransactionTestCase\"><code class=\"xref py py-class docutils literal notranslate\">TransactionTestCase</code></a> instead of\n<a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/tools/#django.test.TestCase\" title=\"django.test.TestCase\"><code class=\"xref py py-class docutils literal notranslate\">TestCase</code></a>.</p>\n</section>\n<section id=\"controlling-creation-order-for-test-databases\">\n<span id=\"topics-testing-creation-dependencies\"></span><h3>Controlling creation order for test databases<a class=\"heading-anchor\" href=\"#controlling-creation-order-for-test-databases\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>By default, Django will assume all databases depend on the <code class=\"docutils literal notranslate\">default</code>\ndatabase and therefore always create the <code class=\"docutils literal notranslate\">default</code> database first.\nHowever, no guarantees are made on the creation order of any other\ndatabases in your test setup.</p>\n<p>If your database configuration requires a specific creation order, you\ncan specify the dependencies that exist using the <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-TEST_DEPENDENCIES\"><code class=\"xref std std-setting docutils literal notranslate\">DEPENDENCIES</code></a> test setting. Consider the following (simplified)\nexample database configuration:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>DATABASES <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"c1\"># ... db settings</span>\n        <span class=\"s2\">&quot;TEST&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;DEPENDENCIES&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;diamonds&quot;</span><span class=\"p\">],</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;diamonds&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"c1\"># ... db settings</span>\n        <span class=\"s2\">&quot;TEST&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;DEPENDENCIES&quot;</span><span class=\"p\">:</span> <span class=\"p\">[],</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;clubs&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"c1\"># ... db settings</span>\n        <span class=\"s2\">&quot;TEST&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;DEPENDENCIES&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;diamonds&quot;</span><span class=\"p\">],</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;spades&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"c1\"># ... db settings</span>\n        <span class=\"s2\">&quot;TEST&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;DEPENDENCIES&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;diamonds&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;hearts&quot;</span><span class=\"p\">],</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;hearts&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"c1\"># ... db settings</span>\n        <span class=\"s2\">&quot;TEST&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;DEPENDENCIES&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"s2\">&quot;diamonds&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;clubs&quot;</span><span class=\"p\">],</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>Under this configuration, the <code class=\"docutils literal notranslate\">diamonds</code> database will be created first,\nas it is the only database alias without dependencies. The <code class=\"docutils literal notranslate\">default</code> and\n<code class=\"docutils literal notranslate\">clubs</code> alias will be created next (although the order of creation of this\npair is not guaranteed), then <code class=\"docutils literal notranslate\">hearts</code>, and finally <code class=\"docutils literal notranslate\">spades</code>.</p>\n<p>If there are any circular dependencies in the <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-TEST_DEPENDENCIES\"><code class=\"xref std std-setting docutils literal notranslate\">DEPENDENCIES</code></a> definition, an\n<a class=\"reference internal\" href=\"/pt-br/4.2/ref/exceptions/#django.core.exceptions.ImproperlyConfigured\" title=\"django.core.exceptions.ImproperlyConfigured\"><code class=\"xref py py-exc docutils literal notranslate\">ImproperlyConfigured</code></a> exception will be raised.</p>\n</section>\n</section>\n<section id=\"advanced-features-of-transactiontestcase\">\n<h2>Advanced features of <code class=\"docutils literal notranslate\">TransactionTestCase</code><a class=\"heading-anchor\" href=\"#advanced-features-of-transactiontestcase\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.test.TransactionTestCase.available_apps\">\n<span class=\"sig-prename descclassname\">TransactionTestCase.</span><span class=\"sig-name descname\">available_apps</span><a class=\"heading-anchor\" href=\"#django.test.TransactionTestCase.available_apps\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Aviso</p>\n<p>This attribute is a private API. It may be changed or removed without\na deprecation period in the future, for instance to accommodate changes\nin application loading.</p>\n<p>It’s used to optimize Django’s own test suite, which contains hundreds\nof models but no relations between models in different applications.</p>\n</aside>\n<p>By default, <code class=\"docutils literal notranslate\">available_apps</code> is set to <code class=\"docutils literal notranslate\">None</code>. After each test, Django\ncalls <a class=\"reference internal\" href=\"/pt-br/4.2/ref/django-admin/#django-admin-flush\"><code class=\"xref std std-djadmin docutils literal notranslate\">flush</code></a> to reset the database state. This empties all tables\nand emits the <a class=\"reference internal\" href=\"/pt-br/4.2/ref/signals/#django.db.models.signals.post_migrate\" title=\"django.db.models.signals.post_migrate\"><code class=\"xref py py-data docutils literal notranslate\">post_migrate</code></a> signal, which\nrecreates one content type and four permissions for each model. This\noperation gets expensive proportionally to the number of models.</p>\n<p>Setting <code class=\"docutils literal notranslate\">available_apps</code> to a list of applications instructs Django to\nbehave as if only the models from these applications were available. The\nbehavior of <code class=\"docutils literal notranslate\">TransactionTestCase</code> changes as follows:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/pt-br/4.2/ref/signals/#django.db.models.signals.post_migrate\" title=\"django.db.models.signals.post_migrate\"><code class=\"xref py py-data docutils literal notranslate\">post_migrate</code></a> is fired before each\ntest to create the content types and permissions for each model in\navailable apps, in case they’re missing.</p></li>\n<li><p>After each test, Django empties only tables corresponding to models in\navailable apps. However, at the database level, truncation may cascade to\nrelated models in unavailable apps. Furthermore\n<a class=\"reference internal\" href=\"/pt-br/4.2/ref/signals/#django.db.models.signals.post_migrate\" title=\"django.db.models.signals.post_migrate\"><code class=\"xref py py-data docutils literal notranslate\">post_migrate</code></a> isn’t fired; it will be\nfired by the next <code class=\"docutils literal notranslate\">TransactionTestCase</code>, after the correct set of\napplications is selected.</p></li>\n</ul>\n<p>Since the database isn’t fully flushed, if a test creates instances of\nmodels not included in <code class=\"docutils literal notranslate\">available_apps</code>, they will leak and they may\ncause unrelated tests to fail. Be careful with tests that use sessions;\nthe default session engine stores them in the database.</p>\n<p>Since <a class=\"reference internal\" href=\"/pt-br/4.2/ref/signals/#django.db.models.signals.post_migrate\" title=\"django.db.models.signals.post_migrate\"><code class=\"xref py py-data docutils literal notranslate\">post_migrate</code></a> isn’t emitted after\nflushing the database, its state after a <code class=\"docutils literal notranslate\">TransactionTestCase</code> isn’t the\nsame as after a <code class=\"docutils literal notranslate\">TestCase</code>: it’s missing the rows created by listeners\nto <a class=\"reference internal\" href=\"/pt-br/4.2/ref/signals/#django.db.models.signals.post_migrate\" title=\"django.db.models.signals.post_migrate\"><code class=\"xref py py-data docutils literal notranslate\">post_migrate</code></a>. Considering the\n<a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/overview/#order-of-tests\"><span class=\"std std-ref\">order in which tests are executed</span></a>, this isn’t an\nissue, provided either all <code class=\"docutils literal notranslate\">TransactionTestCase</code> in a given test suite\ndeclare <code class=\"docutils literal notranslate\">available_apps</code>, or none of them.</p>\n<p><code class=\"docutils literal notranslate\">available_apps</code> is mandatory in Django’s own test suite.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.test.TransactionTestCase.reset_sequences\">\n<span class=\"sig-prename descclassname\">TransactionTestCase.</span><span class=\"sig-name descname\">reset_sequences</span><a class=\"heading-anchor\" href=\"#django.test.TransactionTestCase.reset_sequences\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Setting <code class=\"docutils literal notranslate\">reset_sequences = True</code> on a <code class=\"docutils literal notranslate\">TransactionTestCase</code> will make\nsure sequences are always reset before the test run:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">class</span> <span class=\"nc\">TestsThatDependsOnPrimaryKeySequences</span><span class=\"p\">(</span>TransactionTestCase<span class=\"p\">):</span>\n    reset_sequences <span class=\"o\">=</span> <span class=\"kc\">True</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">test_animal_pk</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        lion <span class=\"o\">=</span> Animal<span class=\"o\">.</span>objects<span class=\"o\">.</span>create<span class=\"p\">(</span>name<span class=\"o\">=</span><span class=\"s2\">&quot;lion&quot;</span><span class=\"p\">,</span> sound<span class=\"o\">=</span><span class=\"s2\">&quot;roar&quot;</span><span class=\"p\">)</span>\n        <span class=\"c1\"># lion.pk is guaranteed to always be 1</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>assertEqual<span class=\"p\">(</span>lion<span class=\"o\">.</span>pk<span class=\"p\">,</span> <span class=\"mi\">1</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Unless you are explicitly testing primary keys sequence numbers, it is\nrecommended that you do not hard code primary key values in tests.</p>\n<p>Using <code class=\"docutils literal notranslate\">reset_sequences = True</code> will slow down the test, since the primary\nkey reset is a relatively expensive database operation.</p>\n</dd></dl>\n\n</section>\n<section id=\"enforce-running-test-classes-sequentially\">\n<span id=\"topics-testing-enforce-run-sequentially\"></span><h2>Enforce running test classes sequentially<a class=\"heading-anchor\" href=\"#enforce-running-test-classes-sequentially\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>If you have test classes that cannot be run in parallel (e.g. because they\nshare a common resource), you can use <code class=\"docutils literal notranslate\">django.test.testcases.SerializeMixin</code>\nto run them sequentially. This mixin uses a filesystem <code class=\"docutils literal notranslate\">lockfile</code>.</p>\n<p>For example, you can use <code class=\"docutils literal notranslate\">__file__</code> to determine that all test classes in the\nsame file that inherit from <code class=\"docutils literal notranslate\">SerializeMixin</code> will run sequentially:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">import</span> <span class=\"nn\">os</span>\n\n<span class=\"kn\">from</span> <span class=\"nn\">django.test</span> <span class=\"kn\">import</span> TestCase\n<span class=\"kn\">from</span> <span class=\"nn\">django.test.testcases</span> <span class=\"kn\">import</span> SerializeMixin\n\n\n<span class=\"k\">class</span> <span class=\"nc\">ImageTestCaseMixin</span><span class=\"p\">(</span>SerializeMixin<span class=\"p\">):</span>\n    lockfile <span class=\"o\">=</span> <span class=\"vm\">__file__</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">setUp</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>filename <span class=\"o\">=</span> os<span class=\"o\">.</span>path<span class=\"o\">.</span>join<span class=\"p\">(</span>temp_storage_dir<span class=\"p\">,</span> <span class=\"s2\">&quot;my_file.png&quot;</span><span class=\"p\">)</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>file <span class=\"o\">=</span> create_file<span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span>filename<span class=\"p\">)</span>\n\n\n<span class=\"k\">class</span> <span class=\"nc\">RemoveImageTests</span><span class=\"p\">(</span>ImageTestCaseMixin<span class=\"p\">,</span> TestCase<span class=\"p\">):</span>\n    <span class=\"k\">def</span> <span class=\"nf\">test_remove_image</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        os<span class=\"o\">.</span>remove<span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span>filename<span class=\"p\">)</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>assertFalse<span class=\"p\">(</span>os<span class=\"o\">.</span>path<span class=\"o\">.</span>exists<span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span>filename<span class=\"p\">))</span>\n\n\n<span class=\"k\">class</span> <span class=\"nc\">ResizeImageTests</span><span class=\"p\">(</span>ImageTestCaseMixin<span class=\"p\">,</span> TestCase<span class=\"p\">):</span>\n    <span class=\"k\">def</span> <span class=\"nf\">test_resize_image</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        resize_image<span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span>file<span class=\"p\">,</span> <span class=\"p\">(</span><span class=\"mi\">48</span><span class=\"p\">,</span> <span class=\"mi\">48</span><span class=\"p\">))</span>\n        <span class=\"bp\">self</span><span class=\"o\">.</span>assertEqual<span class=\"p\">(</span>get_image_size<span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span>file<span class=\"p\">),</span> <span class=\"p\">(</span><span class=\"mi\">48</span><span class=\"p\">,</span> <span class=\"mi\">48</span><span class=\"p\">))</span>\n</code></pre></div>\n</section>\n<section id=\"using-the-django-test-runner-to-test-reusable-applications\">\n<span id=\"testing-reusable-applications\"></span><h2>Using the Django test runner to test reusable applications<a class=\"heading-anchor\" href=\"#using-the-django-test-runner-to-test-reusable-applications\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>If you are writing a <a class=\"reference internal\" href=\"/pt-br/4.2/intro/reusable-apps/\"><span class=\"doc\">reusable application</span></a>\nyou may want to use the Django test runner to run your own test suite\nand thus benefit from the Django testing infrastructure.</p>\n<p>A common practice is a <em>tests</em> directory next to the application code, with the\nfollowing structure:</p>\n<div class=\"code-block\" data-language=\"text\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Text</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Text code\"><code>runtests.py\npolls/\n    __init__.py\n    models.py\n    ...\ntests/\n    __init__.py\n    models.py\n    test_settings.py\n    tests.py\n</code></pre></div>\n<p>Let’s take a look inside a couple of those files:</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\">runtests.py</code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"ch\">#!/usr/bin/env python</span>\n<span class=\"kn\">import</span> <span class=\"nn\">os</span>\n<span class=\"kn\">import</span> <span class=\"nn\">sys</span>\n\n<span class=\"kn\">import</span> <span class=\"nn\">django</span>\n<span class=\"kn\">from</span> <span class=\"nn\">django.conf</span> <span class=\"kn\">import</span> settings\n<span class=\"kn\">from</span> <span class=\"nn\">django.test.utils</span> <span class=\"kn\">import</span> get_runner\n\n<span class=\"k\">if</span> <span class=\"vm\">__name__</span> <span class=\"o\">==</span> <span class=\"s2\">&quot;__main__&quot;</span><span class=\"p\">:</span>\n    os<span class=\"o\">.</span>environ<span class=\"p\">[</span><span class=\"s2\">&quot;DJANGO_SETTINGS_MODULE&quot;</span><span class=\"p\">]</span> <span class=\"o\">=</span> <span class=\"s2\">&quot;tests.test_settings&quot;</span>\n    django<span class=\"o\">.</span>setup<span class=\"p\">()</span>\n    TestRunner <span class=\"o\">=</span> get_runner<span class=\"p\">(</span>settings<span class=\"p\">)</span>\n    test_runner <span class=\"o\">=</span> TestRunner<span class=\"p\">()</span>\n    failures <span class=\"o\">=</span> test_runner<span class=\"o\">.</span>run_tests<span class=\"p\">([</span><span class=\"s2\">&quot;tests&quot;</span><span class=\"p\">])</span>\n    sys<span class=\"o\">.</span>exit<span class=\"p\">(</span><span class=\"nb\">bool</span><span class=\"p\">(</span>failures<span class=\"p\">))</span>\n</code></pre></figure>\n<p>This is the script that you invoke to run the test suite. It sets up the\nDjango environment, creates the test database and runs the tests.</p>\n<p>For the sake of clarity, this example contains only the bare minimum\nnecessary to use the Django test runner. You may want to add\ncommand-line options for controlling verbosity, passing in specific test\nlabels to run, etc.</p>\n<figure class=\"code-block code-block-captioned\" data-language=\"python\"><figcaption class=\"code-block-caption\"><code class=\"docutils literal notranslate\">tests/test_settings.py</code></figcaption>\n<div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code>SECRET_KEY <span class=\"o\">=</span> <span class=\"s2\">&quot;fake-key&quot;</span>\nINSTALLED_APPS <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"s2\">&quot;tests&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></figure>\n<p>This file contains the <a class=\"reference internal\" href=\"/pt-br/4.2/topics/settings/\"><span class=\"doc\">Django settings</span></a>\nrequired to run your app’s tests.</p>\n<p>Again, this is a minimal example; your tests may require additional\nsettings to run.</p>\n<p>Since the <em>tests</em> package is included in <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\">INSTALLED_APPS</code></a> when\nrunning your tests, you can define test-only models in its <code class=\"docutils literal notranslate\">models.py</code>\nfile.</p>\n</section>\n<section id=\"using-different-testing-frameworks\">\n<span id=\"other-testing-frameworks\"></span><h2>Using different testing frameworks<a class=\"heading-anchor\" href=\"#using-different-testing-frameworks\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Clearly, <a class=\"reference external\" href=\"https://docs.python.org/3/library/unittest.html#module-unittest\" title=\"(em Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\">unittest</code></a> is not the only Python testing framework. While Django\ndoesn’t provide explicit support for alternative frameworks, it does provide a\nway to invoke tests constructed for an alternative framework as if they were\nnormal Django tests.</p>\n<p>When you run <code class=\"docutils literal notranslate\">./manage.py test</code>, Django looks at the <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-TEST_RUNNER\"><code class=\"xref std std-setting docutils literal notranslate\">TEST_RUNNER</code></a>\nsetting to determine what to do. By default, <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-TEST_RUNNER\"><code class=\"xref std std-setting docutils literal notranslate\">TEST_RUNNER</code></a> points to\n<code class=\"docutils literal notranslate\">'django.test.runner.DiscoverRunner'</code>. This class defines the default Django\ntesting behavior. This behavior involves:</p>\n<ol class=\"arabic simple\">\n<li><p>Performing global pre-test setup.</p></li>\n<li><p>Looking for tests in any file below the current directory whose name matches\nthe pattern <code class=\"docutils literal notranslate\">test*.py</code>.</p></li>\n<li><p>Creating the test databases.</p></li>\n<li><p>Running <code class=\"docutils literal notranslate\">migrate</code> to install models and initial data into the test\ndatabases.</p></li>\n<li><p>Running the <a class=\"reference internal\" href=\"/pt-br/4.2/topics/checks/\"><span class=\"doc\">system checks</span></a>.</p></li>\n<li><p>Running the tests that were found.</p></li>\n<li><p>Destroying the test databases.</p></li>\n<li><p>Performing global post-test teardown.</p></li>\n</ol>\n<p>If you define your own test runner class and point <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-TEST_RUNNER\"><code class=\"xref std std-setting docutils literal notranslate\">TEST_RUNNER</code></a> at\nthat class, Django will execute your test runner whenever you run\n<code class=\"docutils literal notranslate\">./manage.py test</code>. In this way, it is possible to use any test framework\nthat can be executed from Python code, or to modify the Django test execution\nprocess to satisfy whatever testing requirements you may have.</p>\n<section id=\"defining-a-test-runner\">\n<span id=\"topics-testing-test-runner\"></span><h3>Defining a test runner<a class=\"heading-anchor\" href=\"#defining-a-test-runner\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>A test runner is a class defining a <code class=\"docutils literal notranslate\">run_tests()</code> method. Django ships\nwith a <code class=\"docutils literal notranslate\">DiscoverRunner</code> class that defines the default Django testing\nbehavior. This class defines the <code class=\"docutils literal notranslate\">run_tests()</code> entry point, plus a\nselection of other methods that are used by <code class=\"docutils literal notranslate\">run_tests()</code> to set up, execute\nand tear down the test suite.</p>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">DiscoverRunner</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">pattern<span class=\"o\">=</span><span class=\"default_value\">'test*.py'</span></em>, <em class=\"sig-param\">top_level<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">verbosity<span class=\"o\">=</span><span class=\"default_value\">1</span></em>, <em class=\"sig-param\">interactive<span class=\"o\">=</span><span class=\"default_value\">True</span></em>, <em class=\"sig-param\">failfast<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">keepdb<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">reverse<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">debug_mode<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">debug_sql<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">parallel<span class=\"o\">=</span><span class=\"default_value\">0</span></em>, <em class=\"sig-param\">tags<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">exclude_tags<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">test_name_patterns<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">pdb<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">buffer<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">enable_faulthandler<span class=\"o\">=</span><span class=\"default_value\">True</span></em>, <em class=\"sig-param\">timing<span class=\"o\">=</span><span class=\"default_value\">True</span></em>, <em class=\"sig-param\">shuffle<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">logger<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p><code class=\"docutils literal notranslate\">DiscoverRunner</code> will search for tests in any file matching <code class=\"docutils literal notranslate\">pattern</code>.</p>\n<p><code class=\"docutils literal notranslate\">top_level</code> can be used to specify the directory containing your\ntop-level Python modules. Usually Django can figure this out automatically,\nso it’s not necessary to specify this option. If specified, it should\ngenerally be the directory containing your <code class=\"docutils literal notranslate\">manage.py</code> file.</p>\n<p><code class=\"docutils literal notranslate\">verbosity</code> determines the amount of notification and debug information\nthat will be printed to the console; <code class=\"docutils literal notranslate\">0</code> is no output, <code class=\"docutils literal notranslate\">1</code> is normal\noutput, and <code class=\"docutils literal notranslate\">2</code> is verbose output.</p>\n<p>If <code class=\"docutils literal notranslate\">interactive</code> is <code class=\"docutils literal notranslate\">True</code>, the test suite has permission to ask the\nuser for instructions when the test suite is executed. An example of this\nbehavior would be asking for permission to delete an existing test\ndatabase. If <code class=\"docutils literal notranslate\">interactive</code> is <code class=\"docutils literal notranslate\">False</code>, the test suite must be able to\nrun without any manual intervention.</p>\n<p>If <code class=\"docutils literal notranslate\">failfast</code> is <code class=\"docutils literal notranslate\">True</code>, the test suite will stop running after the\nfirst test failure is detected.</p>\n<p>If <code class=\"docutils literal notranslate\">keepdb</code> is <code class=\"docutils literal notranslate\">True</code>, the test suite will use the existing database,\nor create one if necessary. If <code class=\"docutils literal notranslate\">False</code>, a new database will be created,\nprompting the user to remove the existing one, if present.</p>\n<p>If <code class=\"docutils literal notranslate\">reverse</code> is <code class=\"docutils literal notranslate\">True</code>, test cases will be executed in the opposite\norder. This could be useful to debug tests that aren’t properly isolated\nand have side effects. <a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/overview/#order-of-tests\"><span class=\"std std-ref\">Grouping by test class</span></a> is\npreserved when using this option. This option can be used in conjunction\nwith <code class=\"docutils literal notranslate\">--shuffle</code> to reverse the order for a particular random seed.</p>\n<p><code class=\"docutils literal notranslate\">debug_mode</code> specifies what the <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\">DEBUG</code></a> setting should be\nset to prior to running tests.</p>\n<p><code class=\"docutils literal notranslate\">parallel</code> specifies the number of processes.  If <code class=\"docutils literal notranslate\">parallel</code> is greater\nthan <code class=\"docutils literal notranslate\">1</code>, the test suite will run in <code class=\"docutils literal notranslate\">parallel</code> processes. If there are\nfewer test cases than configured processes, Django will reduce the number\nof processes accordingly. Each process gets its own database. This option\nrequires the third-party <code class=\"docutils literal notranslate\">tblib</code> package to display tracebacks correctly.</p>\n<p><code class=\"docutils literal notranslate\">tags</code> can be used to specify a set of <a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/tools/#topics-tagging-tests\"><span class=\"std std-ref\">tags for filtering tests</span></a>. May be combined with <code class=\"docutils literal notranslate\">exclude_tags</code>.</p>\n<p><code class=\"docutils literal notranslate\">exclude_tags</code> can be used to specify a set of\n<a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/tools/#topics-tagging-tests\"><span class=\"std std-ref\">tags for excluding tests</span></a>. May be combined\nwith <code class=\"docutils literal notranslate\">tags</code>.</p>\n<p>If <code class=\"docutils literal notranslate\">debug_sql</code> is <code class=\"docutils literal notranslate\">True</code>, failing test cases will output SQL queries\nlogged to the <a class=\"reference internal\" href=\"/pt-br/4.2/ref/logging/#django-db-logger\"><span class=\"std std-ref\">django.db.backends logger</span></a> as well\nas the traceback. If <code class=\"docutils literal notranslate\">verbosity</code> is <code class=\"docutils literal notranslate\">2</code>, then queries in all tests are\noutput.</p>\n<p><code class=\"docutils literal notranslate\">test_name_patterns</code> can be used to specify a set of patterns for\nfiltering test methods and classes by their names.</p>\n<p>If <code class=\"docutils literal notranslate\">pdb</code> is <code class=\"docutils literal notranslate\">True</code>, a debugger (<code class=\"docutils literal notranslate\">pdb</code> or <code class=\"docutils literal notranslate\">ipdb</code>) will be spawned at\neach test error or failure.</p>\n<p>If <code class=\"docutils literal notranslate\">buffer</code> is <code class=\"docutils literal notranslate\">True</code>, outputs from passing tests will be discarded.</p>\n<p>If <code class=\"docutils literal notranslate\">enable_faulthandler</code> is <code class=\"docutils literal notranslate\">True</code>, <a class=\"reference external\" href=\"https://docs.python.org/3/library/faulthandler.html#module-faulthandler\" title=\"(em Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\">faulthandler</code></a> will be\nenabled.</p>\n<p>If <code class=\"docutils literal notranslate\">timing</code> is <code class=\"docutils literal notranslate\">True</code>, test timings, including database setup and total\nrun time, will be shown.</p>\n<p>If <code class=\"docutils literal notranslate\">shuffle</code> is an integer, test cases will be shuffled in a random order\nprior to execution, using the integer as a random seed. If <code class=\"docutils literal notranslate\">shuffle</code> is\n<code class=\"docutils literal notranslate\">None</code>, the seed will be generated randomly. In both cases, the seed will\nbe logged and set to <code class=\"docutils literal notranslate\">self.shuffle_seed</code> prior to running tests. This\noption can be used to help detect tests that aren’t properly isolated.\n<a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/overview/#order-of-tests\"><span class=\"std std-ref\">Grouping by test class</span></a> is preserved when using this\noption.</p>\n<p><code class=\"docutils literal notranslate\">logger</code> can be used to pass a Python <a class=\"reference external\" href=\"https://docs.python.org/3/library/logging.html#logger\" title=\"(em Python v3.14)\"><span class=\"xref std std-ref\">Logger object</span></a>.\nIf provided, the logger will be used to log messages instead of printing to\nthe console. The logger object will respect its logging level rather than\nthe <code class=\"docutils literal notranslate\">verbosity</code>.</p>\n<p>Django may, from time to time, extend the capabilities of the test runner\nby adding new arguments. The <code class=\"docutils literal notranslate\">**kwargs</code> declaration allows for this\nexpansion. If you subclass <code class=\"docutils literal notranslate\">DiscoverRunner</code> or write your own test\nrunner, ensure it accepts <code class=\"docutils literal notranslate\">**kwargs</code>.</p>\n<p>Your test runner may also define additional command-line options.\nCreate or override an <code class=\"docutils literal notranslate\">add_arguments(cls, parser)</code> class method and add\ncustom arguments by calling <code class=\"docutils literal notranslate\">parser.add_argument()</code> inside the method, so\nthat the <a class=\"reference internal\" href=\"/pt-br/4.2/ref/django-admin/#django-admin-test\"><code class=\"xref std std-djadmin docutils literal notranslate\">test</code></a> command will be able to use those arguments.</p>\n</dd></dl>\n\n<section id=\"attributes\">\n<h4>Atributos<a class=\"heading-anchor\" href=\"#attributes\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h4>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner.test_suite\">\n<span class=\"sig-prename descclassname\">DiscoverRunner.</span><span class=\"sig-name descname\">test_suite</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner.test_suite\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The class used to build the test suite. By default it is set to\n<code class=\"docutils literal notranslate\">unittest.TestSuite</code>. This can be overridden if you wish to implement\ndifferent logic for collecting tests.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner.test_runner\">\n<span class=\"sig-prename descclassname\">DiscoverRunner.</span><span class=\"sig-name descname\">test_runner</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner.test_runner\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>This is the class of the low-level test runner which is used to execute\nthe individual tests and format the results. By default it is set to\n<code class=\"docutils literal notranslate\">unittest.TextTestRunner</code>. Despite the unfortunate similarity in\nnaming conventions, this is not the same type of class as\n<code class=\"docutils literal notranslate\">DiscoverRunner</code>, which covers a broader set of responsibilities. You\ncan override this attribute to modify the way tests are run and reported.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner.test_loader\">\n<span class=\"sig-prename descclassname\">DiscoverRunner.</span><span class=\"sig-name descname\">test_loader</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner.test_loader\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>This is the class that loads tests, whether from TestCases or modules or\notherwise and bundles them into test suites for the runner to execute.\nBy default it is set to <code class=\"docutils literal notranslate\">unittest.defaultTestLoader</code>. You can override\nthis attribute if your tests are going to be loaded in unusual ways.</p>\n</dd></dl>\n\n</section>\n<section id=\"methods\">\n<h4>Métodos<a class=\"heading-anchor\" href=\"#methods\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h4>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner.run_tests\">\n<span class=\"sig-prename descclassname\">DiscoverRunner.</span><span class=\"sig-name descname\">run_tests</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">test_labels</em>, <em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner.run_tests\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Run the test suite.</p>\n<p><code class=\"docutils literal notranslate\">test_labels</code> allows you to specify which tests to run and supports\nseveral formats (see <a class=\"reference internal\" href=\"#django.test.runner.DiscoverRunner.build_suite\" title=\"django.test.runner.DiscoverRunner.build_suite\"><code class=\"xref py py-meth docutils literal notranslate\">DiscoverRunner.build_suite()</code></a> for a list of\nsupported formats).</p>\n<aside class=\"version-note version-deprecated\" data-version=\"4.0\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 4.0</p><p><span class=\"versionmodified deprecated\">Descontinuado desde a versão 4.0: </span><code class=\"docutils literal notranslate\">extra_tests</code> is a list of extra <code class=\"docutils literal notranslate\">TestCase</code> instances to add to the\nsuite that is executed by the test runner. These extra tests are run in\naddition to those discovered in the modules listed in <code class=\"docutils literal notranslate\">test_labels</code>.</p>\n</aside>\n<p>This method should return the number of tests that failed.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner.add_arguments\">\n<em class=\"property\"><span class=\"k\">classmethod</span> </em><span class=\"sig-prename descclassname\">DiscoverRunner.</span><span class=\"sig-name descname\">add_arguments</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">parser</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner.add_arguments\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Override this class method to add custom arguments accepted by the\n<a class=\"reference internal\" href=\"/pt-br/4.2/ref/django-admin/#django-admin-test\"><code class=\"xref std std-djadmin docutils literal notranslate\">test</code></a> management command. See\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_argument\" title=\"(em Python v3.14)\"><code class=\"xref py py-meth docutils literal notranslate\">argparse.ArgumentParser.add_argument()</code></a> for details about adding\narguments to a parser.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner.setup_test_environment\">\n<span class=\"sig-prename descclassname\">DiscoverRunner.</span><span class=\"sig-name descname\">setup_test_environment</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner.setup_test_environment\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Sets up the test environment by calling\n<a class=\"reference internal\" href=\"#django.test.utils.setup_test_environment\" title=\"django.test.utils.setup_test_environment\"><code class=\"xref py py-func docutils literal notranslate\">setup_test_environment()</code></a> and setting\n<a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\">DEBUG</code></a> to <code class=\"docutils literal notranslate\">self.debug_mode</code> (defaults to <code class=\"docutils literal notranslate\">False</code>).</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner.build_suite\">\n<span class=\"sig-prename descclassname\">DiscoverRunner.</span><span class=\"sig-name descname\">build_suite</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">test_labels<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner.build_suite\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Constructs a test suite that matches the test labels provided.</p>\n<p><code class=\"docutils literal notranslate\">test_labels</code> is a list of strings describing the tests to be run. A test\nlabel can take one of four forms:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">path.to.test_module.TestCase.test_method</code> – Run a single test method\nin a test case.</p></li>\n<li><p><code class=\"docutils literal notranslate\">path.to.test_module.TestCase</code> – Run all the test methods in a test\ncase.</p></li>\n<li><p><code class=\"docutils literal notranslate\">path.to.module</code> – Search for and run all tests in the named Python\npackage or module.</p></li>\n<li><p><code class=\"docutils literal notranslate\">path/to/directory</code> – Search for and run all tests below the named\ndirectory.</p></li>\n</ul>\n<p>If <code class=\"docutils literal notranslate\">test_labels</code> has a value of <code class=\"docutils literal notranslate\">None</code>, the test runner will search for\ntests in all files below the current directory whose names match its\n<code class=\"docutils literal notranslate\">pattern</code> (see above).</p>\n<aside class=\"version-note version-deprecated\" data-version=\"4.0\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 4.0</p><p><span class=\"versionmodified deprecated\">Descontinuado desde a versão 4.0: </span><code class=\"docutils literal notranslate\">extra_tests</code> is a list of extra <code class=\"docutils literal notranslate\">TestCase</code> instances to add to the\nsuite that is executed by the test runner. These extra tests are run in\naddition to those discovered in the modules listed in <code class=\"docutils literal notranslate\">test_labels</code>.</p>\n</aside>\n<p>Returns a <code class=\"docutils literal notranslate\">TestSuite</code> instance ready to be run.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner.setup_databases\">\n<span class=\"sig-prename descclassname\">DiscoverRunner.</span><span class=\"sig-name descname\">setup_databases</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner.setup_databases\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Creates the test databases by calling\n<a class=\"reference internal\" href=\"#django.test.utils.setup_databases\" title=\"django.test.utils.setup_databases\"><code class=\"xref py py-func docutils literal notranslate\">setup_databases()</code></a>.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner.run_checks\">\n<span class=\"sig-prename descclassname\">DiscoverRunner.</span><span class=\"sig-name descname\">run_checks</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">databases</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner.run_checks\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Runs the <a class=\"reference internal\" href=\"/pt-br/4.2/topics/checks/\"><span class=\"doc\">system checks</span></a> on the test <code class=\"docutils literal notranslate\">databases</code>.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner.run_suite\">\n<span class=\"sig-prename descclassname\">DiscoverRunner.</span><span class=\"sig-name descname\">run_suite</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">suite</em>, <em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner.run_suite\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Runs the test suite.</p>\n<p>Returns the result produced by the running the test suite.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner.get_test_runner_kwargs\">\n<span class=\"sig-prename descclassname\">DiscoverRunner.</span><span class=\"sig-name descname\">get_test_runner_kwargs</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner.get_test_runner_kwargs\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the keyword arguments to instantiate the\n<code class=\"docutils literal notranslate\">DiscoverRunner.test_runner</code> with.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner.teardown_databases\">\n<span class=\"sig-prename descclassname\">DiscoverRunner.</span><span class=\"sig-name descname\">teardown_databases</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">old_config</em>, <em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner.teardown_databases\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Destroys the test databases, restoring pre-test conditions by calling\n<a class=\"reference internal\" href=\"#django.test.utils.teardown_databases\" title=\"django.test.utils.teardown_databases\"><code class=\"xref py py-func docutils literal notranslate\">teardown_databases()</code></a>.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner.teardown_test_environment\">\n<span class=\"sig-prename descclassname\">DiscoverRunner.</span><span class=\"sig-name descname\">teardown_test_environment</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner.teardown_test_environment\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Restores the pre-test environment.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner.suite_result\">\n<span class=\"sig-prename descclassname\">DiscoverRunner.</span><span class=\"sig-name descname\">suite_result</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">suite</em>, <em class=\"sig-param\">result</em>, <em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner.suite_result\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Computes and returns a return code based on a test suite, and the result\nfrom that test suite.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.test.runner.DiscoverRunner.log\">\n<span class=\"sig-prename descclassname\">DiscoverRunner.</span><span class=\"sig-name descname\">log</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">msg</em>, <em class=\"sig-param\">level<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.runner.DiscoverRunner.log\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>If a <code class=\"docutils literal notranslate\">logger</code> is set, logs the message at the given integer\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/logging.html#levels\">logging level</a> (e.g. <code class=\"docutils literal notranslate\">logging.DEBUG</code>, <code class=\"docutils literal notranslate\">logging.INFO</code>, or\n<code class=\"docutils literal notranslate\">logging.WARNING</code>). Otherwise, the message is printed to the console,\nrespecting the current <code class=\"docutils literal notranslate\">verbosity</code>. For example, no message will be\nprinted if the <code class=\"docutils literal notranslate\">verbosity</code> is 0, <code class=\"docutils literal notranslate\">INFO</code> and above will be printed if\nthe <code class=\"docutils literal notranslate\">verbosity</code> is at least 1, and <code class=\"docutils literal notranslate\">DEBUG</code> will be printed if it is at\nleast 2. The <code class=\"docutils literal notranslate\">level</code> defaults to <code class=\"docutils literal notranslate\">logging.INFO</code>.</p>\n</dd></dl>\n\n</section>\n</section>\n<section id=\"testing-utilities\">\n<h3>Testing utilities<a class=\"heading-anchor\" href=\"#testing-utilities\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"module-django.test.utils\">\n<span id=\"django-test-utils\"></span><h4><code class=\"docutils literal notranslate\">django.test.utils</code><a class=\"heading-anchor\" href=\"#module-django.test.utils\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>To assist in the creation of your own test runner, Django provides a number of\nutility methods in the <code class=\"docutils literal notranslate\">django.test.utils</code> module.</p>\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.test.utils.setup_test_environment\">\n<span class=\"sig-name descname\">setup_test_environment</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">debug<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.utils.setup_test_environment\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Performs global pre-test setup, such as installing instrumentation for the\ntemplate rendering system and setting up the dummy email outbox.</p>\n<p>If <code class=\"docutils literal notranslate\">debug</code> isn’t <code class=\"docutils literal notranslate\">None</code>, the <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\">DEBUG</code></a> setting is updated to its\nvalue.</p>\n</dd></dl>\n\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.test.utils.teardown_test_environment\">\n<span class=\"sig-name descname\">teardown_test_environment</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.utils.teardown_test_environment\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Performs global post-test teardown, such as removing instrumentation from\nthe template system and restoring normal email services.</p>\n</dd></dl>\n\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.test.utils.setup_databases\">\n<span class=\"sig-name descname\">setup_databases</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">verbosity</em>, <em class=\"sig-param\">interactive</em>, <em class=\"sig-param\"><span class=\"keyword-only-separator o\"><abbr title=\"Separador de parâmetros somente-nomeados (PEP 3102)\">*</abbr></span></em>, <em class=\"sig-param\">time_keeper<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">keepdb<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">debug_sql<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">parallel<span class=\"o\">=</span><span class=\"default_value\">0</span></em>, <em class=\"sig-param\">aliases<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">serialized_aliases<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.utils.setup_databases\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Creates the test databases.</p>\n<p>Returns a data structure that provides enough detail to undo the changes\nthat have been made. This data will be provided to the\n<a class=\"reference internal\" href=\"#django.test.utils.teardown_databases\" title=\"django.test.utils.teardown_databases\"><code class=\"xref py py-func docutils literal notranslate\">teardown_databases()</code></a> function at the conclusion of testing.</p>\n<p>The <code class=\"docutils literal notranslate\">aliases</code> argument determines which <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\">DATABASES</code></a> aliases test\ndatabases should be set up for. If it’s not provided, it defaults to all of\n<a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\">DATABASES</code></a> aliases.</p>\n<p>The <code class=\"docutils literal notranslate\">serialized_aliases</code> argument determines what subset of <code class=\"docutils literal notranslate\">aliases</code>\ntest databases should have their state serialized to allow usage of the\n<a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/overview/#test-case-serialized-rollback\"><span class=\"std std-ref\">serialized_rollback</span></a> feature. If\nit’s not provided, it defaults to <code class=\"docutils literal notranslate\">aliases</code>.</p>\n</dd></dl>\n\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.test.utils.teardown_databases\">\n<span class=\"sig-name descname\">teardown_databases</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">old_config</em>, <em class=\"sig-param\">parallel<span class=\"o\">=</span><span class=\"default_value\">0</span></em>, <em class=\"sig-param\">keepdb<span class=\"o\">=</span><span class=\"default_value\">False</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.test.utils.teardown_databases\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Destroys the test databases, restoring pre-test conditions.</p>\n<p><code class=\"docutils literal notranslate\">old_config</code> is a data structure defining the changes in the database\nconfiguration that need to be reversed. It’s the return value of the\n<a class=\"reference internal\" href=\"#django.test.utils.setup_databases\" title=\"django.test.utils.setup_databases\"><code class=\"xref py py-meth docutils literal notranslate\">setup_databases()</code></a> method.</p>\n</dd></dl>\n\n</section>\n<section id=\"django-db-connection-creation\">\n<h4><code class=\"docutils literal notranslate\">django.db.connection.creation</code><a class=\"heading-anchor\" href=\"#django-db-connection-creation\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The creation module of the database backend also provides some utilities that\ncan be useful during testing.</p>\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.db.connection.creation.create_test_db\">\n<span class=\"sig-name descname\">create_test_db</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">verbosity<span class=\"o\">=</span><span class=\"default_value\">1</span></em>, <em class=\"sig-param\">autoclobber<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">serialize<span class=\"o\">=</span><span class=\"default_value\">True</span></em>, <em class=\"sig-param\">keepdb<span class=\"o\">=</span><span class=\"default_value\">False</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.connection.creation.create_test_db\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Creates a new test database and runs <code class=\"docutils literal notranslate\">migrate</code> against it.</p>\n<p><code class=\"docutils literal notranslate\">verbosity</code> has the same behavior as in <code class=\"docutils literal notranslate\">run_tests()</code>.</p>\n<p><code class=\"docutils literal notranslate\">autoclobber</code> describes the behavior that will occur if a\ndatabase with the same name as the test database is discovered:</p>\n<ul class=\"simple\">\n<li><p>If <code class=\"docutils literal notranslate\">autoclobber</code> is <code class=\"docutils literal notranslate\">False</code>, the user will be asked to\napprove destroying the existing database. <code class=\"docutils literal notranslate\">sys.exit</code> is\ncalled if the user does not approve.</p></li>\n<li><p>If <code class=\"docutils literal notranslate\">autoclobber</code> is <code class=\"docutils literal notranslate\">True</code>, the database will be destroyed\nwithout consulting the user.</p></li>\n</ul>\n<p><code class=\"docutils literal notranslate\">serialize</code> determines if Django serializes the database into an\nin-memory JSON string before running tests (used to restore the database\nstate between tests if you don’t have transactions). You can set this to\n<code class=\"docutils literal notranslate\">False</code> to speed up creation time if you don’t have any test classes\nwith <a class=\"reference internal\" href=\"/pt-br/4.2/topics/testing/overview/#test-case-serialized-rollback\"><span class=\"std std-ref\">serialized_rollback=True</span></a>.</p>\n<p>If you are using the default test runner, you can control this with the\nthe <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-TEST_SERIALIZE\"><code class=\"xref std std-setting docutils literal notranslate\">SERIALIZE</code></a> entry in the <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-DATABASE-TEST\"><code class=\"xref std std-setting docutils literal notranslate\">TEST</code></a> dictionary.</p>\n<p><code class=\"docutils literal notranslate\">keepdb</code> determines if the test run should use an existing\ndatabase, or create a new one. If <code class=\"docutils literal notranslate\">True</code>, the existing\ndatabase will be used, or created if not present. If <code class=\"docutils literal notranslate\">False</code>,\na new database will be created, prompting the user to remove\nthe existing one, if present.</p>\n<p>Returns the name of the test database that it created.</p>\n<p><code class=\"docutils literal notranslate\">create_test_db()</code> has the side effect of modifying the value of\n<a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-NAME\"><code class=\"xref std std-setting docutils literal notranslate\">NAME</code></a> in <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\">DATABASES</code></a> to match the name of the test\ndatabase.</p>\n</dd></dl>\n\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.db.connection.creation.destroy_test_db\">\n<span class=\"sig-name descname\">destroy_test_db</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">old_database_name</em>, <em class=\"sig-param\">verbosity<span class=\"o\">=</span><span class=\"default_value\">1</span></em>, <em class=\"sig-param\">keepdb<span class=\"o\">=</span><span class=\"default_value\">False</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.db.connection.creation.destroy_test_db\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Destroys the database whose name is the value of <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-NAME\"><code class=\"xref std std-setting docutils literal notranslate\">NAME</code></a> in\n<a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-DATABASES\"><code class=\"xref std std-setting docutils literal notranslate\">DATABASES</code></a>, and sets <a class=\"reference internal\" href=\"/pt-br/4.2/ref/settings/#std-setting-NAME\"><code class=\"xref std std-setting docutils literal notranslate\">NAME</code></a> to the value of\n<code class=\"docutils literal notranslate\">old_database_name</code>.</p>\n<p>The <code class=\"docutils literal notranslate\">verbosity</code> argument has the same behavior as for\n<a class=\"reference internal\" href=\"#django.test.runner.DiscoverRunner\" title=\"django.test.runner.DiscoverRunner\"><code class=\"xref py py-class docutils literal notranslate\">DiscoverRunner</code></a>.</p>\n<p>If the <code class=\"docutils literal notranslate\">keepdb</code> argument is <code class=\"docutils literal notranslate\">True</code>, then the connection to the\ndatabase will be closed, but the database will not be destroyed.</p>\n</dd></dl>\n\n</section>\n</section>\n</section>\n<section id=\"integration-with-coverage-py\">\n<span id=\"topics-testing-code-coverage\"></span><h2>Integration with <code class=\"docutils literal notranslate\">coverage.py</code><a class=\"heading-anchor\" href=\"#integration-with-coverage-py\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Code coverage describes how much source code has been tested. It shows which\nparts of your code are being exercised by tests and which are not. It’s an\nimportant part of testing applications, so it’s strongly recommended to check\nthe coverage of your tests.</p>\n<p>Django can be easily integrated with <a class=\"reference external\" href=\"https://coverage.readthedocs.io/\">coverage.py</a>, a tool for measuring code\ncoverage of Python programs. First, install <a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/coverage/\">coverage</a>. Next, run the\nfollowing from your project folder containing <code class=\"docutils literal notranslate\">manage.py</code>:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>coverage run --source<span class=\"o\">=</span><span class=\"s1\">&#39;.&#39;</span> manage.py <span class=\"nb\">test</span> myapp\n</code></pre></div>\n<p>This runs your tests and collects coverage data of the executed files in your\nproject. You can see a report of this data by typing following command:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>coverage report\n</code></pre></div>\n<p>Note that some Django code was executed while running tests, but it is not\nlisted here because of the <code class=\"docutils literal notranslate\">source</code> flag passed to the previous command.</p>\n<p>For more options like annotated HTML listings detailing missed lines, see the\n<a class=\"reference external\" href=\"https://coverage.readthedocs.io/\">coverage.py</a> docs.</p>\n</section>","rootId":"advanced-testing-topics","toc":[{"title":"The request factory","anchor":"the-request-factory","children":[{"title":"Exemplo","anchor":"example","children":[]},{"title":"AsyncRequestFactory","anchor":"asyncrequestfactory","children":[]}]},{"title":"Testing class-based views","anchor":"testing-class-based-views","children":[]},{"title":"Tests and multiple host names","anchor":"tests-and-multiple-host-names","children":[]},{"title":"Tests and multiple databases","anchor":"tests-and-multiple-databases","children":[{"title":"Testing primary/replica configurations","anchor":"testing-primary-replica-configurations","children":[]},{"title":"Controlling creation order for test databases","anchor":"controlling-creation-order-for-test-databases","children":[]}]},{"title":"Advanced features of TransactionTestCase","anchor":"advanced-features-of-transactiontestcase","children":[]},{"title":"Enforce running test classes sequentially","anchor":"enforce-running-test-classes-sequentially","children":[]},{"title":"Using the Django test runner to test reusable applications","anchor":"using-the-django-test-runner-to-test-reusable-applications","children":[]},{"title":"Using different testing frameworks","anchor":"using-different-testing-frameworks","children":[{"title":"Defining a test runner","anchor":"defining-a-test-runner","children":[{"title":"Atributos","anchor":"attributes","children":[]},{"title":"Métodos","anchor":"methods","children":[]}]},{"title":"Testing utilities","anchor":"testing-utilities","children":[{"title":"django.test.utils","anchor":"module-django.test.utils","children":[]},{"title":"django.db.connection.creation","anchor":"django-db-connection-creation","children":[]}]}]},{"title":"Integration with coverage.py","anchor":"integration-with-coverage-py","children":[]}],"breadcrumbs":[{"docname":"topics/index","title":"Usando o Django","url":"/pt-br/4.2/topics/"},{"docname":"topics/testing/index","title":"Testando em Django","url":"/pt-br/4.2/topics/testing/"}],"prev":{"docname":"topics/testing/tools","title":"Testing tools","url":"/pt-br/4.2/topics/testing/tools/"},"next":{"docname":"topics/auth/index","title":"Autenticação de usuário no Django","url":"/pt-br/4.2/topics/auth/"},"formats":{"html":"/pt-br/4.2/topics/testing/advanced/","markdown":"/pt-br/4.2/topics/testing/advanced.md","json":"/pt-br/4.2/topics/testing/advanced.json"},"source":"https://github.com/django/django/blob/stable/4.2.x/docs/topics/testing/advanced.txt","official":"https://docs.djangoproject.com/pt-br/4.2/topics/testing/advanced/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9"],"inLocales":["en","zh-hans","fr","ja","id","it","pt-br","ko","es","el","pl"]}