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

Skip to content

Commit b9fa0a8

Browse files
committed
Raise 'TestSkipped' (from the test_support) module rather than 'ImportError'
to signify a test that should be marked as 'skipped' rather than 'failed'. Also 'document' it, in README.
1 parent 040c17f commit b9fa0a8

10 files changed

Lines changed: 20 additions & 19 deletions

File tree

Lib/test/README

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ functionality. The mechanics of how the test system operates are fairly
1212
straightforward. When a test case is run, the output is compared with the
1313
expected output that is stored in .../Lib/test/output. If the test runs to
1414
completion and the actual and expected outputs match, the test succeeds, if
15-
not, it fails. If an ImportError is raised, the test is not run.
15+
not, it fails. If an ImportError or test_support.TestSkipped error is
16+
raised, the test is not run.
1617

1718
You will be writing unit tests (isolated tests of functions and objects
1819
defined by the module) using white box techniques. Unlike black box

Lib/test/test_binhex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77
import binhex
88
import tempfile
9-
from test_support import verbose
9+
from test_support import verbose, TestSkipped
1010

1111
def test():
1212

@@ -15,7 +15,7 @@ def test():
1515
fname2 = tempfile.mktemp()
1616
f = open(fname1, 'w')
1717
except:
18-
raise ImportError, "Cannot test binhex without a temp file"
18+
raise TestSkipped, "Cannot test binhex without a temp file"
1919

2020
start = 'Jack is my hero'
2121
f.write(start)

Lib/test/test_dl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
import dl
7-
from test_support import verbose
7+
from test_support import verbose,TestSkipped
88

99
sharedlibs = [
1010
('/usr/lib/libc.so', 'getpid'),
@@ -29,4 +29,4 @@
2929
print 'worked!'
3030
break
3131
else:
32-
raise ImportError, 'Could not open any shared libraries'
32+
raise TestSkipped, 'Could not open any shared libraries'

Lib/test/test_fork1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
"""
1010

1111
import os, sys, time, thread
12+
from test_support import TestSkipped
1213

1314
try:
1415
os.fork
1516
except AttributeError:
16-
raise ImportError, "os.fork not defined -- skipping test_fork1"
17+
raise TestSkipped, "os.fork not defined -- skipping test_fork1"
1718

1819
LONGSLEEP = 2
1920

Lib/test/test_gl.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
taken mostly from the documentation.
44
Roger E. Masse
55
"""
6-
from test_support import verbose
6+
from test_support import verbose, TestSkipped
77
import gl, GL, time
88

99
glattrs = ['RGBcolor', 'RGBcursor', 'RGBmode', 'RGBrange', 'RGBwritemask',
@@ -87,8 +87,7 @@ def main():
8787
try:
8888
display = os.environ['DISPLAY']
8989
except:
90-
# Raise ImportError because regrtest.py handles it specially.
91-
raise ImportError, "No $DISPLAY -- skipping gl test"
90+
raise TestSkipped, "No $DISPLAY -- skipping gl test"
9291

9392
# touch all the attributes of gl without doing anything
9493
if verbose:

Lib/test/test_nis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from test_support import verbose, TestFailed
1+
from test_support import verbose, TestFailed, TestSkipped
22
import nis
33

44
print 'nis.maps()'
@@ -9,7 +9,7 @@
99
if verbose:
1010
raise TestFailed, msg
1111
# only do this if running under the regression suite
12-
raise ImportError, msg
12+
raise TestSkipped, msg
1313

1414
done = 0
1515
for nismap in maps:

Lib/test/test_openpty.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Test to see if openpty works. (But don't worry if it isn't available.)
22

33
import os
4-
from test_support import verbose, TestFailed
4+
from test_support import verbose, TestFailed, TestSkipped
55

66
try:
77
if verbose:
@@ -10,7 +10,7 @@
1010
if verbose:
1111
print "(master, slave) = (%d, %d)"%(master, slave)
1212
except AttributeError:
13-
raise ImportError, "No openpty() available."
13+
raise TestSkipped, "No openpty() available."
1414

1515
if not os.isatty(master):
1616
raise TestFailed, "Master-end of pty is not a terminal."

Lib/test/test_pty.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pty, os, sys, string
2-
from test_support import verbose, TestFailed
2+
from test_support import verbose, TestFailed, TestSkipped
33

44
TEST_STRING_1 = "I wish to buy a fish license."
55
TEST_STRING_2 = "For my pet fish, Eric."
@@ -25,7 +25,7 @@ def debug(msg):
2525
debug("Got slave_fd '%d'"%slave_fd)
2626
except OSError:
2727
# " An optional feature could not be imported " ... ?
28-
raise ImportError, "Pseudo-terminals (seemingly) not functional."
28+
raise TestSkipped, "Pseudo-terminals (seemingly) not functional."
2929

3030
if not os.isatty(master_fd):
3131
raise TestFailed, "master_fd is not a tty"

Lib/test/test_signal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Test the signal module
2-
from test_support import verbose
2+
from test_support import verbose, TestSkipped
33
import signal
44
import os
55
import sys
66

77
if sys.platform[:3] in ('win', 'os2'):
8-
raise ImportError, "Can't test signal on %s" % sys.platform[:3]
8+
raise TestSkipped, "Can't test signal on %s" % sys.platform[:3]
99

1010
if verbose:
1111
x = '-x'

Lib/test/test_string.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from test_support import verbose
1+
from test_support import verbose, TestSkipped
22
import string_tests
33
import string, sys
44

55
# XXX: kludge... short circuit if strings don't have methods
66
try:
77
''.join
88
except AttributeError:
9-
raise ImportError
9+
raise TestSkipped
1010

1111
def test(name, input, output, *args):
1212
if verbose:

0 commit comments

Comments
 (0)