@@ -14,7 +14,7 @@ How is PyPy Tested?
14
14
15
15
In this post I want to give an overview of how the PyPy project does and thinks
16
16
about testing. PyPy takes testing quite seriously and has done some from the
17
- start of the project. In the post I want to present the different styles of
17
+ start of the project. Here I want to present the different styles of
18
18
tests that PyPy has, when we use them and how I think about them.
19
19
20
20
@@ -116,7 +116,7 @@ just completely regular Python 2 classes that behave in the regular way when
116
116
run on top of a Python interpreter.
117
117
118
118
In CPython, these tests don't really have an equivalent. They would correspond
119
- to tests that are written in C and that can access test the logic of all the C
119
+ to tests that are written in C and that can test the logic of all the C
120
120
functions of CPython that execute certain functionality, accessing the internals
121
121
of C structs in the process. `¹ `_
122
122
@@ -181,27 +181,30 @@ The CPython Test Suite
181
181
We also use the CPython Test suite as a final check to see whether our
182
182
interpreter correctly implements all the features of the Python language. In
183
183
that sense it acts as some kind of compliance test suite that checks whether we
184
- implement the language correctly. The test suite is not perfect for this
185
- purpose. Since it is written for CPython's purposes during its development, a
184
+ implement the language correctly. The test suite is not perfect for this.
185
+ Since it is written for CPython's purposes during its development, a
186
186
lot of the tests check really specific CPython implementation details. Examples
187
187
for these are tests that check that ``__del__ `` is called immediately after
188
188
objects go out of scope (which only happens if you use reference counting as a
189
- garbage collection strategy, which PyPy doesn't do). Other examples are checking
189
+ garbage collection strategy, PyPy uses a `different approach to garbage
190
+ collection `_). Other examples are checking
190
191
for exception error messages very explicitly. However, the CPython test suite
191
192
has gotten a lot better in these regards over time, by adding
192
193
``support.gc_collect() `` calls to fix the former problem, and by marking some
193
194
very specific tests with the ``@impl_detail `` decorator. Thanks to all the
194
195
CPython developers who have worked on this!
195
196
197
+ .. _`different approach to garbage collection` : https://www.pypy.org/posts/2013/10/incremental-garbage-collector-in-pypy-8956893523842234676.html
198
+
196
199
In the process of re-implementing CPython's functionality and running CPython's
197
200
tests suite, PyPy can often also be a good way to find bugs in CPython. While we
198
201
think about the corner cases of some Python feature we occasionally find
199
202
situations where CPython didn't get everything completely correct either, which
200
203
we then report back.
201
204
202
205
203
- Testing Performance
204
- =====================
206
+ Testing for Performance Regressions
207
+ ====================================
205
208
206
209
All the tests we described so far are checking *behaviour *. But one of PyPy's
207
210
important goals is to be a *fast * implementation not "just" a correct one. Some
@@ -221,7 +224,7 @@ representation`_ that the JIT uses to produce machine code from.
221
224
.. _`intermediate representation` : https://www.pypy.org/posts/2018/09/the-first-15-years-of-pypy-3412615975376972020.html
222
225
223
226
As an example, here is a small test that loading the attribute of a constant
224
- global instance can be completely constant folded away
227
+ global instance can be completely constant folded away:
225
228
226
229
.. code :: python
227
230
@@ -290,7 +293,7 @@ Footnotes
290
293
291
294
.. _`¹` :
292
295
293
- CPython has the `_testcapimodule.c ` and related modules, that are used to
296
+ ¹ CPython has the `_testcapimodule.c ` and related modules, that are used to
294
297
unit-test the C-API. However, these are still driven from Python tests using
295
298
the ``unittest `` framework and wouldn't run without the Python interpreter
296
299
already working.
@@ -304,8 +307,8 @@ then having a test class with the pattern ``class AppTest*``. We haven't
304
307
converted all of them to the new style yet, even though the old style is
305
308
quite weird: since the ``test_*.py `` files are themselves parsed by
306
309
Python 2, the tests methods in ``AppTest* `` classes need to be written in the
307
- subset of Python 3 that is also valid Python 2 syntax, leading to a lot of
308
- confusion.
310
+ subset of Python 3 syntax that is also valid Python 2 syntax, leading to a lot
311
+ of confusion.
309
312
310
313
.. _`³` :
311
314
0 commit comments