Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3b816f8

Browse files
committed
Tweak tests for PyPy and add CI runner
* `autoreload` tests are skipped on PyPy because `gc.get_referrers` is unusably slow here * `doctest_refs` does not seem to test anything and was removed * pexpect timeouts were adjusted because subprocess communication is 3-4 times slower on PyPy * few other tweaks
1 parent e447487 commit 3b816f8

12 files changed

Lines changed: 55 additions & 40 deletions

File tree

.github/workflows/test.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ jobs:
3333
- os: ubuntu-latest
3434
python-version: "3.11-dev"
3535
deps: test
36+
# Installing optional dependencies stuff takes ages on PyPy
37+
- os: ubuntu-latest
38+
python-version: "pypy-3.8"
39+
deps: test
40+
- os: windows-latest
41+
python-version: "pypy-3.8"
42+
deps: test
43+
- os: macos-latest
44+
python-version: "pypy-3.8"
45+
deps: test
3646

3747
steps:
3848
- uses: actions/checkout@v2

IPython/core/tests/test_async_helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
Should only trigger on python 3.5+ or will have syntax errors.
55
"""
6+
import platform
67
from itertools import chain, repeat
78
from textwrap import dedent, indent
89
from unittest import TestCase
@@ -275,7 +276,7 @@ def test_autoawait(self):
275276
"""
276277
)
277278

278-
if sys.version_info < (3,9):
279+
if sys.version_info < (3, 9) and platform.python_implementation() != "PyPy":
279280
# new pgen parser in 3.9 does not raise MemoryError on too many nested
280281
# parens anymore
281282
def test_memory_error(self):

IPython/core/tests/test_debugger.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,13 @@ def _decorator_skip_setup():
371371
child = pexpect.spawn(
372372
sys.executable, ["-m", "IPython", "--colors=nocolor"], env=env
373373
)
374-
child.timeout = 5 * IPYTHON_TESTING_TIMEOUT_SCALE
374+
child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE
375375

376376
child.expect("IPython")
377377
child.expect("\n")
378378

379+
child.timeout = 5 * IPYTHON_TESTING_TIMEOUT_SCALE
380+
379381
dedented_blocks = [dedent(b).strip() for b in skip_decorators_blocks]
380382
in_prompt_number = 1
381383
for cblock in dedented_blocks:
@@ -448,11 +450,13 @@ def test_decorator_skip_with_breakpoint():
448450
child = pexpect.spawn(
449451
sys.executable, ["-m", "IPython", "--colors=nocolor"], env=env
450452
)
451-
child.timeout = 5 * IPYTHON_TESTING_TIMEOUT_SCALE
453+
child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE
452454

453455
child.expect("IPython")
454456
child.expect("\n")
455457

458+
child.timeout = 5 * IPYTHON_TESTING_TIMEOUT_SCALE
459+
456460
### we need a filename, so we need to exec the full block with a filename
457461
with NamedTemporaryFile(suffix=".py", dir=".", delete=True) as tf:
458462

IPython/core/tests/test_magic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""Tests for various magic functions."""
33

44
import asyncio
5+
import gc
56
import io
67
import os
78
import re
@@ -576,6 +577,7 @@ def test_xdel(self):
576577
_ip.magic("xdel a")
577578

578579
# Check that a's __del__ method has been called.
580+
gc.collect(0)
579581
assert monitor == [1]
580582

581583
def doctest_who():

IPython/core/tests/test_run.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import functools
2020
import os
21+
import platform
2122
from os.path import join as pjoin
2223
import random
2324
import string
@@ -158,7 +159,7 @@ def doctest_reset_del():
158159
159160
In [3]: a = A()
160161
161-
In [4]: get_ipython().reset()
162+
In [4]: get_ipython().reset(); import gc; x = gc.collect(0)
162163
Hi
163164
164165
In [5]: 1+1
@@ -241,6 +242,10 @@ def test_simpledef(self):
241242
_ip.run_cell("t = isinstance(f(), foo)")
242243
assert _ip.user_ns["t"] is True
243244

245+
@pytest.mark.xfail(
246+
platform.python_implementation() == "PyPy",
247+
reason="expecting __del__ call on exit is unreliable and doesn't happen on PyPy",
248+
)
244249
def test_obj_del(self):
245250
"""Test that object's __del__ methods are called on exit."""
246251
src = ("class A(object):\n"
@@ -286,14 +291,20 @@ def test_run_second(self):
286291
_ip.magic("run %s" % empty.fname)
287292
assert _ip.user_ns["afunc"]() == 1
288293

289-
@dec.skip_win32
290294
def test_tclass(self):
291295
mydir = os.path.dirname(__file__)
292-
tc = os.path.join(mydir, 'tclass')
293-
src = ("%%run '%s' C-first\n"
294-
"%%run '%s' C-second\n"
295-
"%%run '%s' C-third\n") % (tc, tc, tc)
296-
self.mktmp(src, '.ipy')
296+
tc = os.path.join(mydir, "tclass")
297+
src = f"""\
298+
import gc
299+
%run "{tc}" C-first
300+
gc.collect(0)
301+
%run "{tc}" C-second
302+
gc.collect(0)
303+
%run "{tc}" C-third
304+
gc.collect(0)
305+
%reset -f
306+
"""
307+
self.mktmp(src, ".ipy")
297308
out = """\
298309
ARGV 1-: ['C-first']
299310
ARGV 1-: ['C-second']

IPython/core/tests/test_ultratb.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
import io
55
import logging
6+
import platform
67
import re
78
import sys
89
import os.path
@@ -248,7 +249,8 @@ def test_non_syntaxerror(self):
248249
ip.showsyntaxerror()
249250

250251
import sys
251-
if sys.version_info < (3,9):
252+
253+
if sys.version_info < (3, 9) and platform.python_implementation() != "PyPy":
252254
"""
253255
New 3.9 Pgen Parser does not raise Memory error, except on failed malloc.
254256
"""
@@ -359,7 +361,7 @@ def test_recursion_one_frame(self):
359361
):
360362
ip.run_cell("r1()")
361363

362-
@recursionlimit(200)
364+
@recursionlimit(160)
363365
def test_recursion_three_frames(self):
364366
with tt.AssertPrints("[... skipping similar frames: "), \
365367
tt.AssertPrints(re.compile(r"r3a at line 8 \(\d{2} times\)"), suppress=False), \

IPython/extensions/tests/test_autoreload.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# -----------------------------------------------------------------------------
1414

1515
import os
16+
import platform
17+
import pytest
1618
import sys
1719
import tempfile
1820
import textwrap
@@ -28,6 +30,12 @@
2830
from IPython.extensions.autoreload import AutoreloadMagics
2931
from IPython.core.events import EventManager, pre_run_cell
3032

33+
if platform.python_implementation() == "PyPy":
34+
pytest.skip(
35+
"Current autoreload implementation is extremly slow on PyPy",
36+
allow_module_level=True,
37+
)
38+
3139
# -----------------------------------------------------------------------------
3240
# Test fixture
3341
# -----------------------------------------------------------------------------

IPython/terminal/tests/test_debug_magic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def test_debug_magic_passes_through_generators():
5151
child.sendline(" pass")
5252
child.sendline("")
5353

54+
child.timeout = 10 * IPYTHON_TESTING_TIMEOUT_SCALE
55+
5456
child.expect('Exception:')
5557

5658
child.expect(in_prompt)

IPython/terminal/tests/test_embed.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ def test_nest_embed():
7474

7575
child = pexpect.spawn(sys.executable, ['-m', 'IPython', '--colors=nocolor'],
7676
env=env)
77-
child.timeout = 5 * IPYTHON_TESTING_TIMEOUT_SCALE
77+
child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE
7878
child.expect(ipy_prompt)
79+
child.timeout = 5 * IPYTHON_TESTING_TIMEOUT_SCALE
7980
child.sendline("import IPython")
8081
child.expect(ipy_prompt)
8182
child.sendline("ip0 = get_ipython()")

IPython/testing/plugin/show_refs.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)