You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The recommended way to run tests is using Django's built-in test runner, which is what CI uses:
28
+
29
+
.. code-block:: bash
30
+
31
+
# Run all tests (this may take some time!)
32
+
docker exec intranet_django python ./manage.py test --noinput
33
+
34
+
# Run tests for a specific app (in this case, polls)
35
+
docker exec intranet_django python ./manage.py test intranet.apps.polls --noinput
36
+
37
+
# Run a specific test file (in this case, auth)
38
+
docker exec intranet_django python ./manage.py test intranet.apps.auth.tests.TurnstileFieldTest --noinput
39
+
40
+
# Run with verbose output, useful for debugging
41
+
docker exec intranet_django python ./manage.py test intranet.apps.polls --noinput -v 2
42
+
43
+
Interactive Testing Shell
44
+
-------------------------
45
+
46
+
If you want to run multiple test commands, you can open an interactive shell with Docker:
47
+
48
+
.. code-block:: bash
49
+
50
+
docker exec -it intranet_django sh
16
51
17
-
To actually execute tests, run ``pytest`` inside your dev environment. If you want to only test a specific app, you can run ``pytest <apps_name>``. Do note that this deletes and re-creates the db from scratch each time, so you may want to pass the ``-k`` option when developing tests as it significantly reduces run-time.
52
+
# then inside the container, run tests:
53
+
./manage.py test intranet.apps.polls --noinput
18
54
19
55
Coverage
20
56
========
@@ -42,8 +78,8 @@ The first is calling methods directly; the second is making a GET or POST reques
42
78
The best tests utilize both. After you do either/both of these to call the code, you should use assertions to see if the code behaved as expected.
43
79
A list of assertion options can be found `here <https://docs.python.org/3/library/unittest.html#assert-methods>`_.
44
80
A useful tool for making requests to the view is ``self.client``. More documentation on that can be found
45
-
`here <https://docs.djangoproject.com/en/3.2/topics/testing/tools/>`_. Alternatively, just search through Ion's
46
-
testing files for examples of using `self.client`.
81
+
`here <https://docs.djangoproject.com/en/stable/topics/testing/tools/>`_. Alternatively, just search through Ion's
82
+
testing files for examples of using ``self.client``.
47
83
48
84
Good Testing Examples
49
85
=====================
@@ -57,8 +93,8 @@ Ion has lots of tests; the following are examples of very well-written ones. Not
0 commit comments