Debian Codegraph @

doc/internal/testing.rst

raw
1 Testing pyglet
2 ==============
3
4 Test Suites
5 -----------
6 Tests for pyglet are divided into 3 suites.
7
8 Unit tests
9 ''''''''''
10
11 Unit tests only cover a single unit of code or a combination of a
12 limited number of units. No resource intensive computations should
13 be included. These tests should run in limited time without
14 any user interaction.
15
16 Integration tests
17 '''''''''''''''''
18
19 Integration tests cover the integration of components of pyglet
20 into the whole of pyglet and the integration into the supported systems.
21 Like unit tests these tests do not require user interaction,
22 but they can take longer to run due to access to system resources.
23
24 Interactive tests
25 '''''''''''''''''
26
27 Interactive tests require the user to verify whether the test is
28 successful and in some cases require the user to perform actions
29 in order for the test to continue. These tests can take a
30 long time to run.
31
32 There are currently 3 types of interactive test cases:
33
34 - Tests that can only run in fully interactive mode as they require
35 the user to perform an action in order for the test to continue.
36 These tests are decorated with
37 :func:`~tests.interactive.interactive_test_base.requires_user_action`.
38 - Tests that can run without user interaction, but that cannot validate
39 whether they should pass or fail. These tests are decorated with
40 :func:`~tests.interactive.interactive_test_base.requires_user_validation`.
41 - Tests that can run without user interaction and that can compare results
42 to screenshots from a previous run to determine whether they pass or
43 fail. This is the default type.
44
45 Running tests
46 -------------
47
48 The pyglet test suite is based on the `pytest framework <http://pytest.org>`_.
49
50 It is strongly preferred to use a virtual environment to run the tests.
51 For instructions to set up virtual environments see :doc:`virtualenv`.
52
53 Make sure of the following when running tests:
54
55 1. The virtual environment for the Python version you want to
56 test is active.
57 2. You are running tests against currently supported Python versions.
58
59 Ideally, you should also test against the minimum supported Python
60 version (currently |min_python_version|) to make sure your changes
61 are compatible with all supported Python versions.
62
63 To run all tests, execute pytest in the root of the pyglet repository::
64
65 pytest
66
67 You can also run just a single suite::
68
69 pytest tests/unit
70 pytest tests/integration
71 pytest tests/interactive
72
73 For the interactive test suites, there are some extra command line switches
74 for pytest:
75
76 - ``--non-interactive``: Only run the interactive tests that can only
77 verify themselves using screenshots. The screenshots are created when
78 you run the tests in interactive mode, so you will need to run the tests
79 interactively once, before you can use this option;
80 - ``--sanity``: Do a sanity check by running as many interactive tests
81 without user intervention. Not all tests can run without intervention,
82 so these tests will still be skipped. Mostly useful to quickly check
83 changes in code. Not all tests perform complete validation.
84
85 Writing tests
86 -------------
87
88 Annotations
89 '''''''''''
90
91 Some control over test execution can be exerted by using annotations in
92 the form of decorators. One function of annotations is to skip tests
93 under certain conditions.
94
95 General annotations
96 ^^^^^^^^^^^^^^^^^^^
97
98 General test annotations are available in the module :mod:`tests.annotations`.
99
100 .. py:currentmodule:: tests.annotations
101 .. py:decorator:: require_platform(platform)
102
103 Only run the test on the given platform(s), skip on other platforms.
104
105 :param list(str) platform: A list of platform identifiers as returned by
106 :data:`pyglet.options`. See also :class:`~tests.annotations.Platform`.
107
108 .. py:decorator:: skip_platform(platform)
109
110 Skip test on the given platform(s).
111
112 :param list(str) platform: A list of platform identifiers as returned by
113 :data:`pyglet.options`. See also :class:`~tests.annotations.Platform`.
114
115 .. autoclass:: tests.annotations.Platform
116 :members:
117
118 .. py:decorator:: require_gl_extension(extension)
119
120 Skip the test if the given GL extension is not available.
121
122 :param str extension: Name of the extension required.
123
124 Suite annotations
125 ^^^^^^^^^^^^^^^^^
126
127 This is currently not used.
128
129 .. py:decorator:: pytest.mark.unit
130
131 Test belongs to the unit test suite.
132
133 .. py:decorator:: pytest.mark.integration
134
135 Test belongs to the integration test suite.
136
137 .. py:decorator:: pytest.mark.interactive
138
139 Test belongs to the interactive test suite.
140
141 Interactive test annotations
142 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
143
144 Interactive test cases can be marked with specific pytest marks. Currently
145 the following marks are used:
146
147 .. py:decorator:: pytest.mark.requires_user_action
148
149 Test requires user interaction to run. It needs to be skipped when running in
150 non-interactive or sanity mode.
151
152 .. py:decorator:: pytest.mark.requires_user_validation
153
154 User validation is required to mark the test passed or failed. However the test
155 can run in sanity mode.
156
157 .. py:decorator:: pytest.mark.only_interactive
158
159 For another reason the test can only run in interactive mode.
160