1. ==========
    
  2. Unit tests
    
  3. ==========
    
  4. 
    
  5. Django comes with a test suite of its own, in the ``tests`` directory of the
    
  6. code base. It's our policy to make sure all tests pass at all times.
    
  7. 
    
  8. We appreciate any and all contributions to the test suite!
    
  9. 
    
  10. The Django tests all use the testing infrastructure that ships with Django for
    
  11. testing applications. See :doc:`/topics/testing/overview` for an explanation of
    
  12. how to write new tests.
    
  13. 
    
  14. .. _running-unit-tests:
    
  15. 
    
  16. Running the unit tests
    
  17. ======================
    
  18. 
    
  19. Quickstart
    
  20. ----------
    
  21. 
    
  22. First, `fork Django on GitHub <https://github.com/django/django/fork>`__.
    
  23. 
    
  24. Second, create and activate a virtual environment. If you're not familiar with
    
  25. how to do that, read our :doc:`contributing tutorial </intro/contributing>`.
    
  26. 
    
  27. Next, clone your fork, install some requirements, and run the tests:
    
  28. 
    
  29. .. console::
    
  30. 
    
  31.    $ git clone https://github.com/YourGitHubName/django.git django-repo
    
  32.    $ cd django-repo/tests
    
  33.    $ python -m pip install -e ..
    
  34.    $ python -m pip install -r requirements/py3.txt
    
  35.    $ ./runtests.py
    
  36. 
    
  37. Installing the requirements will likely require some operating system packages
    
  38. that your computer doesn't have installed. You can usually figure out which
    
  39. package to install by doing a web search for the last line or so of the error
    
  40. message. Try adding your operating system to the search query if needed.
    
  41. 
    
  42. If you have trouble installing the requirements, you can skip that step. See
    
  43. :ref:`running-unit-tests-dependencies` for details on installing the optional
    
  44. test dependencies. If you don't have an optional dependency installed, the
    
  45. tests that require it will be skipped.
    
  46. 
    
  47. Running the tests requires a Django settings module that defines the databases
    
  48. to use. To help you get started, Django provides and uses a sample settings
    
  49. module that uses the SQLite database. See :ref:`running-unit-tests-settings` to
    
  50. learn how to use a different settings module to run the tests with a different
    
  51. database.
    
  52. 
    
  53. Having problems? See :ref:`troubleshooting-unit-tests` for some common issues.
    
  54. 
    
  55. Running tests using ``tox``
    
  56. ---------------------------
    
  57. 
    
  58. `Tox <https://tox.wiki/>`_ is a tool for running tests in different virtual
    
  59. environments. Django includes a basic ``tox.ini`` that automates some checks
    
  60. that our build server performs on pull requests. To run the unit tests and
    
  61. other checks (such as :ref:`import sorting <coding-style-imports>`, the
    
  62. :ref:`documentation spelling checker <documentation-spelling-check>`, and
    
  63. :ref:`code formatting <coding-style-python>`), install and run the ``tox``
    
  64. command from any place in the Django source tree:
    
  65. 
    
  66. .. console::
    
  67. 
    
  68.     $ python -m pip install tox
    
  69.     $ tox
    
  70. 
    
  71. By default, ``tox`` runs the test suite with the bundled test settings file for
    
  72. SQLite, ``black``, ``flake8``, ``isort``, and the documentation spelling
    
  73. checker. In addition to the system dependencies noted elsewhere in this
    
  74. documentation, the command ``python3`` must be on your path and linked to the
    
  75. appropriate version of Python. A list of default environments can be seen as
    
  76. follows:
    
  77. 
    
  78. .. console::
    
  79. 
    
  80.     $ tox -l
    
  81.     py3
    
  82.     black
    
  83.     flake8>=3.7.0
    
  84.     docs
    
  85.     isort>=5.1.0
    
  86. 
    
  87. Testing other Python versions and database backends
    
  88. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  89. 
    
  90. In addition to the default environments, ``tox`` supports running unit tests
    
  91. for other versions of Python and other database backends. Since Django's test
    
  92. suite doesn't bundle a settings file for database backends other than SQLite,
    
  93. however, you must :ref:`create and provide your own test settings
    
  94. <running-unit-tests-settings>`. For example, to run the tests on Python 3.9
    
  95. using PostgreSQL:
    
  96. 
    
  97. .. console::
    
  98. 
    
  99.     $ tox -e py39-postgres -- --settings=my_postgres_settings
    
  100. 
    
  101. This command sets up a Python 3.9 virtual environment, installs Django's
    
  102. test suite dependencies (including those for PostgreSQL), and calls
    
  103. ``runtests.py`` with the supplied arguments (in this case,
    
  104. ``--settings=my_postgres_settings``).
    
  105. 
    
  106. The remainder of this documentation shows commands for running tests without
    
  107. ``tox``, however, any option passed to ``runtests.py`` can also be passed to
    
  108. ``tox`` by prefixing the argument list with ``--``, as above.
    
  109. 
    
  110. ``Tox`` also respects the :envvar:`DJANGO_SETTINGS_MODULE` environment
    
  111. variable, if set. For example, the following is equivalent to the command
    
  112. above:
    
  113. 
    
  114. .. code-block:: console
    
  115. 
    
  116.     $ DJANGO_SETTINGS_MODULE=my_postgres_settings tox -e py39-postgres
    
  117. 
    
  118. Windows users should use:
    
  119. 
    
  120. .. code-block:: doscon
    
  121. 
    
  122.     ...\> set DJANGO_SETTINGS_MODULE=my_postgres_settings
    
  123.     ...\> tox -e py39-postgres
    
  124. 
    
  125. Running the JavaScript tests
    
  126. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  127. 
    
  128. Django includes a set of :ref:`JavaScript unit tests <javascript-tests>` for
    
  129. functions in certain contrib apps. The JavaScript tests aren't run by default
    
  130. using ``tox`` because they require ``Node.js`` to be installed and aren't
    
  131. necessary for the majority of patches. To run the JavaScript tests using
    
  132. ``tox``:
    
  133. 
    
  134. .. console::
    
  135. 
    
  136.     $ tox -e javascript
    
  137. 
    
  138. This command runs ``npm install`` to ensure test requirements are up to
    
  139. date and then runs ``npm test``.
    
  140. 
    
  141. Running tests using ``django-docker-box``
    
  142. -----------------------------------------
    
  143. 
    
  144. `django-docker-box`_ allows you to run the Django's test suite across all
    
  145. supported databases and python versions. See the `django-docker-box`_ project
    
  146. page for installation and usage instructions.
    
  147. 
    
  148. .. _django-docker-box: https://github.com/django/django-docker-box/
    
  149. 
    
  150. .. _running-unit-tests-settings:
    
  151. 
    
  152. Using another ``settings`` module
    
  153. ---------------------------------
    
  154. 
    
  155. The included settings module (``tests/test_sqlite.py``) allows you to run the
    
  156. test suite using SQLite. If you want to run the tests using a different
    
  157. database, you'll need to define your own settings file. Some tests, such as
    
  158. those for ``contrib.postgres``, are specific to a particular database backend
    
  159. and will be skipped if run with a different backend. Some tests are skipped or
    
  160. expected failures on a particular database backend (see
    
  161. ``DatabaseFeatures.django_test_skips`` and
    
  162. ``DatabaseFeatures.django_test_expected_failures`` on each backend).
    
  163. 
    
  164. To run the tests with different settings, ensure that the module is on your
    
  165. :envvar:`PYTHONPATH` and pass the module with ``--settings``.
    
  166. 
    
  167. The :setting:`DATABASES` setting in any test settings module needs to define
    
  168. two databases:
    
  169. 
    
  170. * A ``default`` database. This database should use the backend that
    
  171.   you want to use for primary testing.
    
  172. 
    
  173. * A database with the alias ``other``. The ``other`` database is used to test
    
  174.   that queries can be directed to different databases. This database should use
    
  175.   the same backend as the ``default``, and it must have a different name.
    
  176. 
    
  177. If you're using a backend that isn't SQLite, you will need to provide other
    
  178. details for each database:
    
  179. 
    
  180. * The :setting:`USER` option needs to specify an existing user account
    
  181.   for the database. That user needs permission to execute ``CREATE DATABASE``
    
  182.   so that the test database can be created.
    
  183. 
    
  184. * The :setting:`PASSWORD` option needs to provide the password for
    
  185.   the :setting:`USER` that has been specified.
    
  186. 
    
  187. Test databases get their names by prepending ``test_`` to the value of the
    
  188. :setting:`NAME` settings for the databases defined in :setting:`DATABASES`.
    
  189. These test databases are deleted when the tests are finished.
    
  190. 
    
  191. You will also need to ensure that your database uses UTF-8 as the default
    
  192. character set. If your database server doesn't use UTF-8 as a default charset,
    
  193. you will need to include a value for :setting:`CHARSET <TEST_CHARSET>` in the
    
  194. test settings dictionary for the applicable database.
    
  195. 
    
  196. .. _runtests-specifying-labels:
    
  197. 
    
  198. Running only some of the tests
    
  199. ------------------------------
    
  200. 
    
  201. Django's entire test suite takes a while to run, and running every single test
    
  202. could be redundant if, say, you just added a test to Django that you want to
    
  203. run quickly without running everything else. You can run a subset of the unit
    
  204. tests by appending the names of the test modules to ``runtests.py`` on the
    
  205. command line.
    
  206. 
    
  207. For example, if you'd like to run tests only for generic relations and
    
  208. internationalization, type:
    
  209. 
    
  210. .. console::
    
  211. 
    
  212.    $ ./runtests.py --settings=path.to.settings generic_relations i18n
    
  213. 
    
  214. How do you find out the names of individual tests? Look in ``tests/`` — each
    
  215. directory name there is the name of a test.
    
  216. 
    
  217. If you want to run only a particular class of tests, you can specify a list of
    
  218. paths to individual test classes. For example, to run the ``TranslationTests``
    
  219. of the ``i18n`` module, type:
    
  220. 
    
  221. .. console::
    
  222. 
    
  223.    $ ./runtests.py --settings=path.to.settings i18n.tests.TranslationTests
    
  224. 
    
  225. Going beyond that, you can specify an individual test method like this:
    
  226. 
    
  227. .. console::
    
  228. 
    
  229.    $ ./runtests.py --settings=path.to.settings i18n.tests.TranslationTests.test_lazy_objects
    
  230. 
    
  231. You can run tests starting at a specified top-level module with ``--start-at``
    
  232. option. For example:
    
  233. 
    
  234. .. console::
    
  235. 
    
  236.    $ ./runtests.py --start-at=wsgi
    
  237. 
    
  238. You can also run tests starting after a specified top-level module with
    
  239. ``--start-after`` option. For example:
    
  240. 
    
  241. .. console::
    
  242. 
    
  243.    $ ./runtests.py --start-after=wsgi
    
  244. 
    
  245. Note that the ``--reverse`` option doesn't impact on ``--start-at`` or
    
  246. ``--start-after`` options. Moreover these options cannot be used with test
    
  247. labels.
    
  248. 
    
  249. Running the Selenium tests
    
  250. --------------------------
    
  251. 
    
  252. Some tests require Selenium and a web browser. To run these tests, you must
    
  253. install the selenium_ package and run the tests with the
    
  254. ``--selenium=<BROWSERS>`` option. For example, if you have Firefox and Google
    
  255. Chrome installed:
    
  256. 
    
  257. .. console::
    
  258. 
    
  259.    $ ./runtests.py --selenium=firefox,chrome
    
  260. 
    
  261. See the `selenium.webdriver`_ package for the list of available browsers.
    
  262. 
    
  263. Specifying ``--selenium`` automatically sets ``--tags=selenium`` to run only
    
  264. the tests that require selenium.
    
  265. 
    
  266. Some browsers (e.g. Chrome or Firefox) support headless testing, which can be
    
  267. faster and more stable. Add the ``--headless`` option to enable this mode.
    
  268. 
    
  269. .. _selenium.webdriver: https://github.com/SeleniumHQ/selenium/tree/trunk/py/selenium/webdriver
    
  270. 
    
  271. .. _running-unit-tests-dependencies:
    
  272. 
    
  273. Running all the tests
    
  274. ---------------------
    
  275. 
    
  276. If you want to run the full suite of tests, you'll need to install a number of
    
  277. dependencies:
    
  278. 
    
  279. *  aiosmtpd_
    
  280. *  argon2-cffi_ 19.1.0+
    
  281. *  asgiref_ 3.5.2+ (required)
    
  282. *  bcrypt_
    
  283. *  colorama_
    
  284. *  docutils_
    
  285. *  geoip2_
    
  286. *  jinja2_ 2.7+
    
  287. *  numpy_
    
  288. *  Pillow_ 6.2.0+
    
  289. *  PyYAML_
    
  290. *  pytz_ (required)
    
  291. *  pywatchman_
    
  292. *  redis_
    
  293. *  setuptools_
    
  294. *  memcached_, plus a :ref:`supported Python binding <memcached>`
    
  295. *  gettext_ (:ref:`gettext_on_windows`)
    
  296. *  selenium_
    
  297. *  sqlparse_ 0.2.2+ (required)
    
  298. *  tblib_ 1.5.0+
    
  299. 
    
  300. You can find these dependencies in `pip requirements files`_ inside the
    
  301. ``tests/requirements`` directory of the Django source tree and install them
    
  302. like so:
    
  303. 
    
  304. .. console::
    
  305. 
    
  306.    $ python -m pip install -r tests/requirements/py3.txt
    
  307. 
    
  308. If you encounter an error during the installation, your system might be missing
    
  309. a dependency for one or more of the Python packages. Consult the failing
    
  310. package's documentation or search the web with the error message that you
    
  311. encounter.
    
  312. 
    
  313. You can also install the database adapter(s) of your choice using
    
  314. ``oracle.txt``, ``mysql.txt``, or ``postgres.txt``.
    
  315. 
    
  316. If you want to test the memcached or Redis cache backends, you'll also need to
    
  317. define a :setting:`CACHES` setting that points at your memcached or Redis
    
  318. instance respectively.
    
  319. 
    
  320. To run the GeoDjango tests, you will need to :doc:`set up a spatial database
    
  321. and install the Geospatial libraries</ref/contrib/gis/install/index>`.
    
  322. 
    
  323. Each of these dependencies is optional. If you're missing any of them, the
    
  324. associated tests will be skipped.
    
  325. 
    
  326. To run some of the autoreload tests, you'll need to install the Watchman_
    
  327. service.
    
  328. 
    
  329. .. _aiosmtpd: https://pypi.org/project/aiosmtpd/
    
  330. .. _argon2-cffi: https://pypi.org/project/argon2-cffi/
    
  331. .. _asgiref: https://pypi.org/project/asgiref/
    
  332. .. _bcrypt: https://pypi.org/project/bcrypt/
    
  333. .. _colorama: https://pypi.org/project/colorama/
    
  334. .. _docutils: https://pypi.org/project/docutils/
    
  335. .. _geoip2: https://pypi.org/project/geoip2/
    
  336. .. _jinja2: https://pypi.org/project/Jinja2/
    
  337. .. _numpy: https://pypi.org/project/numpy/
    
  338. .. _Pillow: https://pypi.org/project/Pillow/
    
  339. .. _PyYAML: https://pyyaml.org/wiki/PyYAML
    
  340. .. _pytz: https://pypi.org/project/pytz/
    
  341. .. _pywatchman: https://pypi.org/project/pywatchman/
    
  342. .. _redis: https://pypi.org/project/redis/
    
  343. .. _setuptools: https://pypi.org/project/setuptools/
    
  344. .. _memcached: https://memcached.org/
    
  345. .. _gettext: https://www.gnu.org/software/gettext/manual/gettext.html
    
  346. .. _selenium: https://pypi.org/project/selenium/
    
  347. .. _sqlparse: https://pypi.org/project/sqlparse/
    
  348. .. _pip requirements files: https://pip.pypa.io/en/latest/user_guide/#requirements-files
    
  349. .. _tblib: https://pypi.org/project/tblib/
    
  350. .. _Watchman: https://facebook.github.io/watchman/
    
  351. 
    
  352. Code coverage
    
  353. -------------
    
  354. 
    
  355. Contributors are encouraged to run coverage on the test suite to identify areas
    
  356. that need additional tests. The coverage tool installation and use is described
    
  357. in :ref:`testing code coverage<topics-testing-code-coverage>`.
    
  358. 
    
  359. Coverage should be run in a single process to obtain accurate statistics. To
    
  360. run coverage on the Django test suite using the standard test settings:
    
  361. 
    
  362. .. console::
    
  363. 
    
  364.    $ coverage run ./runtests.py --settings=test_sqlite --parallel=1
    
  365. 
    
  366. After running coverage, generate the html report by running:
    
  367. 
    
  368. .. console::
    
  369. 
    
  370.    $ coverage html
    
  371. 
    
  372. When running coverage for the Django tests, the included ``.coveragerc``
    
  373. settings file  defines ``coverage_html`` as the output directory for the report
    
  374. and also excludes several directories not relevant to the results
    
  375. (test code or external code included in Django).
    
  376. 
    
  377. .. _contrib-apps:
    
  378. 
    
  379. Contrib apps
    
  380. ============
    
  381. 
    
  382. Tests for contrib apps can be found in the ``tests/`` directory, typically
    
  383. under ``<app_name>_tests``. For example, tests for ``contrib.auth`` are located
    
  384. in ``tests/auth_tests``.
    
  385. 
    
  386. .. _troubleshooting-unit-tests:
    
  387. 
    
  388. Troubleshooting
    
  389. ===============
    
  390. 
    
  391. Test suite hangs or shows failures on ``main`` branch
    
  392. -----------------------------------------------------
    
  393. 
    
  394. Ensure you have the latest point release of a :ref:`supported Python version
    
  395. <faq-python-version-support>`, since there are often bugs in earlier versions
    
  396. that may cause the test suite to fail or hang.
    
  397. 
    
  398. On **macOS** (High Sierra and newer versions), you might see this message
    
  399. logged, after which the tests hang::
    
  400. 
    
  401.     objc[42074]: +[__NSPlaceholderDate initialize] may have been in progress in
    
  402.     another thread when fork() was called.
    
  403. 
    
  404. To avoid this set a ``OBJC_DISABLE_INITIALIZE_FORK_SAFETY`` environment
    
  405. variable, for example::
    
  406. 
    
  407.     $ OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES ./runtests.py
    
  408. 
    
  409. Or add ``export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES`` to your shell's
    
  410. startup file (e.g. ``~/.profile``).
    
  411. 
    
  412. Many test failures with ``UnicodeEncodeError``
    
  413. ----------------------------------------------
    
  414. 
    
  415. If the ``locales`` package is not installed, some tests will fail with a
    
  416. ``UnicodeEncodeError``.
    
  417. 
    
  418. You can resolve this on Debian-based systems, for example, by running:
    
  419. 
    
  420. .. code-block:: console
    
  421. 
    
  422.     $ apt-get install locales
    
  423.     $ dpkg-reconfigure locales
    
  424. 
    
  425. You can resolve this for macOS systems by configuring your shell's locale:
    
  426. 
    
  427. .. code-block:: console
    
  428. 
    
  429.     $ export LANG="en_US.UTF-8"
    
  430.     $ export LC_ALL="en_US.UTF-8"
    
  431. 
    
  432. Run the ``locale`` command to confirm the change. Optionally, add those export
    
  433. commands to your shell's startup file (e.g. ``~/.bashrc`` for Bash) to avoid
    
  434. having to retype them.
    
  435. 
    
  436. Tests that only fail in combination
    
  437. -----------------------------------
    
  438. 
    
  439. In case a test passes when run in isolation but fails within the whole suite,
    
  440. we have some tools to help analyze the problem.
    
  441. 
    
  442. The ``--bisect`` option of ``runtests.py`` will run the failing test while
    
  443. halving the test set it is run together with on each iteration, often making
    
  444. it possible to identify a small number of tests that may be related to the
    
  445. failure.
    
  446. 
    
  447. For example, suppose that the failing test that works on its own is
    
  448. ``ModelTest.test_eq``, then using:
    
  449. 
    
  450. .. console::
    
  451. 
    
  452.     $ ./runtests.py --bisect basic.tests.ModelTest.test_eq
    
  453. 
    
  454. will try to determine a test that interferes with the given one. First, the
    
  455. test is run with the first half of the test suite. If a failure occurs, the
    
  456. first half of the test suite is split in two groups and each group is then run
    
  457. with the specified test. If there is no failure with the first half of the test
    
  458. suite, the second half of the test suite is run with the specified test and
    
  459. split appropriately as described earlier. The process repeats until the set of
    
  460. failing tests is minimized.
    
  461. 
    
  462. The ``--pair`` option runs the given test alongside every other test from the
    
  463. suite, letting you check if another test has side-effects that cause the
    
  464. failure. So:
    
  465. 
    
  466. .. console::
    
  467. 
    
  468.     $ ./runtests.py --pair basic.tests.ModelTest.test_eq
    
  469. 
    
  470. will pair ``test_eq`` with every test label.
    
  471. 
    
  472. With both ``--bisect`` and ``--pair``, if you already suspect which cases
    
  473. might be responsible for the failure, you may limit tests to be cross-analyzed
    
  474. by :ref:`specifying further test labels <runtests-specifying-labels>` after
    
  475. the first one:
    
  476. 
    
  477. .. console::
    
  478. 
    
  479.     $ ./runtests.py --pair basic.tests.ModelTest.test_eq queries transactions
    
  480. 
    
  481. You can also try running any set of tests in a random or reverse order using
    
  482. the ``--shuffle`` and ``--reverse`` options. This can help verify that
    
  483. executing tests in a different order does not cause any trouble:
    
  484. 
    
  485. .. console::
    
  486. 
    
  487.     $ ./runtests.py basic --shuffle
    
  488.     $ ./runtests.py basic --reverse
    
  489. 
    
  490. Seeing the SQL queries run during a test
    
  491. ----------------------------------------
    
  492. 
    
  493. If you wish to examine the SQL being run in failing tests, you can turn on
    
  494. :ref:`SQL logging <django-db-logger>` using the ``--debug-sql`` option. If you
    
  495. combine this with ``--verbosity=2``, all SQL queries will be output:
    
  496. 
    
  497. .. console::
    
  498. 
    
  499.     $ ./runtests.py basic --debug-sql
    
  500. 
    
  501. Seeing the full traceback of a test failure
    
  502. -------------------------------------------
    
  503. 
    
  504. By default tests are run in parallel with one process per core. When the tests
    
  505. are run in parallel, however, you'll only see a truncated traceback for any
    
  506. test failures. You can adjust this behavior with the ``--parallel`` option:
    
  507. 
    
  508. .. console::
    
  509. 
    
  510.     $ ./runtests.py basic --parallel=1
    
  511. 
    
  512. You can also use the :envvar:`DJANGO_TEST_PROCESSES` environment variable for
    
  513. this purpose.
    
  514. 
    
  515. Tips for writing tests
    
  516. ======================
    
  517. 
    
  518. .. highlight:: python
    
  519. 
    
  520. Isolating model registration
    
  521. ----------------------------
    
  522. 
    
  523. To avoid polluting the global :attr:`~django.apps.apps` registry and prevent
    
  524. unnecessary table creation, models defined in a test method should be bound to
    
  525. a temporary ``Apps`` instance. To do this, use the
    
  526. :func:`~django.test.utils.isolate_apps` decorator::
    
  527. 
    
  528.     from django.db import models
    
  529.     from django.test import SimpleTestCase
    
  530.     from django.test.utils import isolate_apps
    
  531. 
    
  532.     class TestModelDefinition(SimpleTestCase):
    
  533.         @isolate_apps('app_label')
    
  534.         def test_model_definition(self):
    
  535.             class TestModel(models.Model):
    
  536.                 pass
    
  537.             ...
    
  538. 
    
  539. .. admonition:: Setting ``app_label``
    
  540. 
    
  541.     Models defined in a test method with no explicit
    
  542.     :attr:`~django.db.models.Options.app_label` are automatically assigned the
    
  543.     label of the app in which their test class is located.
    
  544. 
    
  545.     In order to make sure the models defined within the context of
    
  546.     :func:`~django.test.utils.isolate_apps` instances are correctly
    
  547.     installed, you should pass the set of targeted ``app_label`` as arguments:
    
  548. 
    
  549.     .. code-block:: python
    
  550.         :caption: ``tests/app_label/tests.py``
    
  551. 
    
  552.         from django.db import models
    
  553.         from django.test import SimpleTestCase
    
  554.         from django.test.utils import isolate_apps
    
  555. 
    
  556.         class TestModelDefinition(SimpleTestCase):
    
  557.             @isolate_apps('app_label', 'other_app_label')
    
  558.             def test_model_definition(self):
    
  559.                 # This model automatically receives app_label='app_label'
    
  560.                 class TestModel(models.Model):
    
  561.                     pass
    
  562. 
    
  563.                 class OtherAppModel(models.Model):
    
  564.                     class Meta:
    
  565.                         app_label = 'other_app_label'
    
  566.                 ...