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

Skip to content

Commit ea4ab3a

Browse files
CarreauMatthias Bussonnier
authored andcommitted
Also run test with Pytest.
This now run many of the tests using pytest. Many of previous pull-requests brought pytest compatibility; this now actually would run a passing test suite. This does not mean we can drop nose; in particular we still have plugins fro doctests using iptest; which pytest does not run; and we are still limited to pytest 3 (pytest 4 does not support yield-test anymore) There is thus still much work to do.
1 parent 32cf29f commit ea4ab3a

11 files changed

Lines changed: 92 additions & 19 deletions

File tree

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ install:
3939
- pip install setuptools --upgrade
4040
- pip install -e file://$PWD#egg=ipython[test] --upgrade
4141
- pip install trio curio
42+
- pip install 'pytest<4' matplotlib
4243
- pip install codecov check-manifest --upgrade
4344

4445
script:
@@ -49,6 +50,7 @@ script:
4950
cp /home/travis/virtualenv/python3.8-dev/lib/python3.8/site-packages/parso/python/grammar37.txt /home/travis/virtualenv/python3.8-dev/lib/python3.8/site-packages/parso/python/grammar38.txt
5051
fi
5152
- cd /tmp && iptest --coverage xml && cd -
53+
- pytest IPython
5254
# On the latest Python (on Linux) only, make sure that the docs build.
5355
- |
5456
if [[ "$TRAVIS_PYTHON_VERSION" == "3.7" ]] && [[ "$TRAVIS_OS_NAME" == "linux" ]]; then

IPython/conftest.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import types
2+
import sys
3+
import builtins
4+
import os
5+
import pytest
6+
import pathlib
7+
import shutil
8+
9+
from IPython.testing import tools
10+
11+
12+
def get_ipython():
13+
from IPython.terminal.interactiveshell import TerminalInteractiveShell
14+
if TerminalInteractiveShell._instance:
15+
return TerminalInteractiveShell.instance()
16+
17+
config = tools.default_config()
18+
config.TerminalInteractiveShell.simple_prompt = True
19+
20+
# Create and initialize our test-friendly IPython instance.
21+
shell = TerminalInteractiveShell.instance(config=config)
22+
return shell
23+
24+
25+
@pytest.fixture(scope='session', autouse=True)
26+
def work_path():
27+
path = pathlib.Path("./tmp-ipython-pytest-profiledir")
28+
os.environ["IPYTHONDIR"] = str(path.absolute())
29+
if path.exists():
30+
raise ValueError('IPython dir temporary path already exists ! Did previous test run exit successfully ?')
31+
path.mkdir()
32+
yield
33+
shutil.rmtree(str(path.resolve()))
34+
35+
36+
def nopage(strng, start=0, screen_lines=0, pager_cmd=None):
37+
if isinstance(strng, dict):
38+
strng = strng.get("text/plain", "")
39+
print(strng)
40+
41+
42+
def xsys(self, cmd):
43+
"""Replace the default system call with a capturing one for doctest.
44+
"""
45+
# We use getoutput, but we need to strip it because pexpect captures
46+
# the trailing newline differently from commands.getoutput
47+
print(self.getoutput(cmd, split=False, depth=1).rstrip(), end="", file=sys.stdout)
48+
sys.stdout.flush()
49+
50+
51+
# for things to work correctly we would need this as a session fixture;
52+
# unfortunately this will fail on some test that get executed as _collection_
53+
# time (before the fixture run), in particular parametrized test that contain
54+
# yields. so for now execute at import time.
55+
#@pytest.fixture(autouse=True, scope='session')
56+
def inject():
57+
58+
builtins.get_ipython = get_ipython
59+
builtins._ip = get_ipython()
60+
builtins.ip = get_ipython()
61+
builtins.ip.system = types.MethodType(xsys, ip)
62+
builtins.ip.builtin_trap.activate()
63+
from IPython.core import page
64+
65+
page.pager_page = nopage
66+
# yield
67+
68+
69+
inject()

IPython/core/tests/test_alias.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ def test_alias_args_error():
3939
_ip.run_cell('parts 1')
4040

4141
nt.assert_equal(cap.stderr.split(':')[0], 'UsageError')
42-
42+
4343
def test_alias_args_commented():
4444
"""Check that alias correctly ignores 'commented out' args"""
4545
_ip.magic('alias commetarg echo this is %%s a commented out arg')
4646

4747
with capture_output() as cap:
4848
_ip.run_cell('commetarg')
4949

50-
nt.assert_equal(cap.stdout, 'this is %s a commented out arg')
50+
# strip() is for pytest compat; testing via iptest patch IPython shell
51+
# in testin.globalipapp and replace the system call which messed up the
52+
# \r\n
53+
assert cap.stdout.strip() == 'this is %s a commented out arg'
5154

5255
def test_alias_args_commented_nargs():
5356
"""Check that alias correctly counts args, excluding those commented out"""
@@ -59,4 +62,4 @@ def test_alias_args_commented_nargs():
5962
assert am.is_alias(alias_name)
6063

6164
thealias = am.get_alias(alias_name)
62-
nt.assert_equal(thealias.nargs, 1)
65+
nt.assert_equal(thealias.nargs, 1)

IPython/core/tests/test_magic.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
from IPython.utils.process import find_cmd
3434

3535

36-
37-
_ip = get_ipython()
38-
3936
@magic.magics_class
4037
class DummyMagics(magic.Magics): pass
4138

@@ -150,6 +147,7 @@ def test_rehashx():
150147
# rehashx must fill up syscmdlist
151148
scoms = _ip.db['syscmdlist']
152149
nt.assert_true(len(scoms) > 10)
150+
153151

154152

155153
def test_magic_parse_options():

IPython/core/tests/test_magic_terminal.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515

1616
from IPython.testing import tools as tt
1717

18-
#-----------------------------------------------------------------------------
19-
# Globals
20-
#-----------------------------------------------------------------------------
21-
2218
#-----------------------------------------------------------------------------
2319
# Test functions begin
2420
#-----------------------------------------------------------------------------

IPython/core/tests/test_oinspect.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323
# Globals and constants
2424
#-----------------------------------------------------------------------------
2525

26-
inspector = oinspect.Inspector()
27-
ip = get_ipython()
26+
inspector = None
27+
28+
def setup_module():
29+
global inspector
30+
inspector = oinspect.Inspector()
31+
2832

2933
#-----------------------------------------------------------------------------
3034
# Local utilities
@@ -34,7 +38,7 @@
3438
# defined, if any code is inserted above, the following line will need to be
3539
# updated. Do NOT insert any whitespace between the next line and the function
3640
# definition below.
37-
THIS_LINE_NUMBER = 37 # Put here the actual number of this line
41+
THIS_LINE_NUMBER = 41 # Put here the actual number of this line
3842

3943
from unittest import TestCase
4044

@@ -123,7 +127,6 @@ def method(self, x, z=2):
123127
"""Some method's docstring"""
124128

125129

126-
127130
class Awkward(object):
128131
def __getattr__(self, name):
129132
raise Exception(name)
@@ -221,7 +224,6 @@ def support_function_one(x, y=2, *a, **kw):
221224
def test_calldef_none():
222225
# We should ignore __call__ for all of these.
223226
for obj in [support_function_one, SimpleClass().method, any, str.upper]:
224-
print(obj)
225227
i = inspector.info(obj)
226228
nt.assert_is(i['call_def'], None)
227229

IPython/external/decorators/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
try:
2-
from numpy.testing.noseclasses import KnownFailure, knownfailureif
2+
from numpy.testing import KnownFailure, knownfailureif
33
except ImportError:
44
from ._decorators import knownfailureif
55
try:

IPython/testing/iptestcontroller.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __init__(self):
4949
self.env = {}
5050
self.dirs = []
5151

52-
def setup(self):
52+
def setUp(self):
5353
"""Create temporary directories etc.
5454
5555
This is only called when we know the test group will be run. Things
@@ -440,7 +440,6 @@ def find_code_units(self, morfs):
440440
'all tests.')
441441
argparser.add_argument('--all', action='store_true',
442442
help='Include slow tests not run by default.')
443-
argparser.add_argument('--url', help="URL to use for the JS tests.")
444443
argparser.add_argument('-j', '--fast', nargs='?', const=None, default=1, type=int,
445444
help='Run test sections in parallel. This starts as many '
446445
'processes as you have cores, or you can specify a number.')

IPython/testing/ipunittest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import re
3939
import unittest
4040
from doctest import DocTestFinder, DocTestRunner, TestResults
41+
from IPython.terminal.interactiveshell import InteractiveShell
4142

4243
#-----------------------------------------------------------------------------
4344
# Classes and functions
@@ -78,7 +79,7 @@ def __call__(self, ds):
7879
dnew = self.rps1.sub(pyps1, dnew)
7980
dnew = self.rps2.sub(pyps2, dnew)
8081
dnew = self.rout.sub(pyout, dnew)
81-
ip = globalipapp.get_ipython()
82+
ip = InteractiveShell.instance()
8283

8384
# Convert input IPython source into valid Python.
8485
out = []

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ include LICENSE
44
include setupbase.py
55
include setupegg.py
66
include MANIFEST.in
7+
include pytest.ini
78
include .mailmap
89

910
recursive-exclude tools *

0 commit comments

Comments
 (0)