[Zope3-checkins]
SVN: zope.testing/trunk/src/zope/testing/testrunner
Handle attempts to use pdb for tests running in layers run in
Jim Fulton
jim at zope.com
Wed Jul 13 08:02:58 EDT 2005
Log message for revision 33295:
Handle attempts to use pdb for tests running in layers run in
subprocesses. We can't use pdb in these situations, but the test
runner needs to detect such attempts and provide some informative
output -- rather than hang.
Changed:
A zope.testing/trunk/src/zope/testing/testrunner-ex/sample1/sampletests_ntds.py
A zope.testing/trunk/src/zope/testing/testrunner-ex/sample2/sampletests_ntds.py
U zope.testing/trunk/src/zope/testing/testrunner.py
U zope.testing/trunk/src/zope/testing/testrunner.txt
-=-
Added: zope.testing/trunk/src/zope/testing/testrunner-ex/sample1/sampletests_ntds.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner-ex/sample1/sampletests_ntds.py 2005-07-13 10:56:36 UTC (rev 33294)
+++ zope.testing/trunk/src/zope/testing/testrunner-ex/sample1/sampletests_ntds.py 2005-07-13 12:02:58 UTC (rev 33295)
@@ -0,0 +1,46 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Sample tests with a layer that can't be torn down
+
+$Id$
+"""
+
+import unittest
+
+class Layer:
+
+ def setUp(self):
+ pass
+ setUp = classmethod(setUp)
+
+ def tearDown(self):
+ raise NotImplementedError
+ tearDown = classmethod(tearDown)
+
+class TestSomething(unittest.TestCase):
+
+ layer = Layer
+
+ def test_something(self):
+ pass
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestSomething))
+ return suite
+
+
+if __name__ == '__main__':
+ unittest.main()
Property changes on: zope.testing/trunk/src/zope/testing/testrunner-ex/sample1/sampletests_ntds.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope.testing/trunk/src/zope/testing/testrunner-ex/sample2/sampletests_ntds.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner-ex/sample2/sampletests_ntds.py 2005-07-13 10:56:36 UTC (rev 33294)
+++ zope.testing/trunk/src/zope/testing/testrunner-ex/sample2/sampletests_ntds.py 2005-07-13 12:02:58 UTC (rev 33295)
@@ -0,0 +1,77 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Sample tests with a layer that can't be torn down
+
+$Id$
+"""
+
+import unittest
+from zope.testing import doctest
+
+class Layer:
+
+ def setUp(self):
+ pass
+ setUp = classmethod(setUp)
+
+ def tearDown(self):
+ raise NotImplementedError
+ tearDown = classmethod(tearDown)
+
+class TestSomething(unittest.TestCase):
+
+ layer = Layer
+
+ def test_something(self):
+ import pdb; pdb.set_trace()
+
+ def test_something2(self):
+ import pdb; pdb.set_trace()
+
+ def test_something3(self):
+ import pdb; pdb.set_trace()
+
+ def test_something4(self):
+ import pdb; pdb.set_trace()
+
+ def test_something5(self):
+ f()
+
+def f():
+ import pdb; pdb.set_trace()
+
+def test_set_trace():
+ """
+ >>> if 1:
+ ... x = 1
+ ... import pdb; pdb.set_trace()
+ """
+
+def test_set_trace2():
+ """
+ >>> f()
+ """
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestSomething))
+ d = doctest.DocTestSuite()
+ d.layer = Layer
+ suite.addTest(d)
+ return suite
+
+
+if __name__ == '__main__':
+ unittest.main()
Property changes on: zope.testing/trunk/src/zope/testing/testrunner-ex/sample2/sampletests_ntds.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: zope.testing/trunk/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner.py 2005-07-13 10:56:36 UTC (rev 33294)
+++ zope.testing/trunk/src/zope/testing/testrunner.py 2005-07-13 12:02:58 UTC (rev 33295)
@@ -52,10 +52,11 @@
args.pop(1)
resume_layer = args.pop(1)
defaults = []
- while args[1] == '--default':
+ while len(args) > 1 and args[1] == '--default':
args.pop(1)
defaults.append(args.pop(1))
+ sys.stdin = FakeInputContinueGenerator()
else:
resume_layer = None
@@ -463,6 +464,18 @@
%s
"""
+class FakeInputContinueGenerator:
+
+ def readline(self):
+ print 'c\n'
+ print '*'*70
+ print ("Can't use pdb.set_trace when running a layer"
+ " as a subprocess!")
+ print '*'*70
+ print
+ return 'c\n'
+
+
def print_traceback(msg, exc_info):
print
print msg
@@ -1119,6 +1132,7 @@
import renormalizing
checker = renormalizing.RENormalizing([
+ (re.compile('^> [^\n]+->None$', re.M), '> ...->None'),
(re.compile('\\\\'), '/'), # hopefully, we'll make windows happy
(re.compile('/r'), '\\\\r'), # undo damage from previous
(re.compile(r'\r'), '\\\\r\n'),
@@ -1137,6 +1151,8 @@
(re.compile(r'^ +File "[^\n]+(doc|unit)test.py", [^\n]+\n[^\n]+\n',
re.MULTILINE),
r''),
+ (re.compile('^> [^\n]+->None$', re.M), '> ...->None'),
+ (re.compile('import pdb; pdb'), 'Pdb()'), # Py 2.3
])
Modified: zope.testing/trunk/src/zope/testing/testrunner.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner.txt 2005-07-13 10:56:36 UTC (rev 33294)
+++ zope.testing/trunk/src/zope/testing/testrunner.txt 2005-07-13 12:02:58 UTC (rev 33295)
@@ -1634,7 +1634,7 @@
If this is the case and there are no remaining tests to run, the test
runner will just note that the tear down couldn't be done:
- >>> sys.argv = 'test -ssample2 --tests-pattern sampletests_ntd'.split()
+ >>> sys.argv = 'test -ssample2 --tests-pattern sampletests_ntd$'.split()
>>> testrunner.run(defaults)
Running sample2.sampletests_ntd.Layer tests:
Set up sample2.sampletests_ntd.Layer in 0.000 seconds.
@@ -1646,7 +1646,7 @@
layers to run, the test runner will restart itself as a new process,
resuming tests where it left off:
- >>> sys.argv = [testrunner_script, '--tests-pattern', 'sampletests_ntd']
+ >>> sys.argv = [testrunner_script, '--tests-pattern', 'sampletests_ntd$']
>>> testrunner.run(defaults)
Running sample1.sampletests_ntd.Layer tests:
Set up sample1.sampletests_ntd.Layer in N.NNN seconds.
@@ -1703,7 +1703,7 @@
Note that debugging doesn't work when running tests in a subprocess:
- >>> sys.argv = [testrunner_script, '--tests-pattern', 'sampletests_ntd',
+ >>> sys.argv = [testrunner_script, '--tests-pattern', 'sampletests_ntd$',
... '-D', ]
>>> testrunner.run(defaults)
Running sample1.sampletests_ntd.Layer tests:
@@ -1774,3 +1774,87 @@
Tearing down left over layers:
Tear down sample3.sampletests_ntd.Layer ... not supported
Total: 0 tests, 0 failures, 4 errors
+
+Similarly, pdb.set_trace doesn't work when running tests in a layer
+that is run as a subprocess:
+
+ >>> sys.argv = [testrunner_script, '--tests-pattern', 'sampletests_ntds']
+ >>> testrunner.run(defaults)
+ Running sample1.sampletests_ntds.Layer tests:
+ Set up sample1.sampletests_ntds.Layer in 0.000 seconds.
+ Ran 1 tests with 0 failures and 0 errors in 0.000 seconds.
+ Running sample2.sampletests_ntds.Layer tests:
+ Tear down sample1.sampletests_ntds.Layer ... not supported
+ Running sample2.sampletests_ntds.Layer tests:
+ Set up sample2.sampletests_ntds.Layer in 0.000 seconds.
+ --Return--
+ > testrunner-ex/sample2/sampletests_ntds.py(37)test_something()->None
+ -> import pdb; pdb.set_trace()
+ (Pdb) c
+ <BLANKLINE>
+ **********************************************************************
+ Can't use pdb.set_trace when running a layer as a subprocess!
+ **********************************************************************
+ <BLANKLINE>
+ --Return--
+ > testrunner-ex/sample2/sampletests_ntds.py(40)test_something2()->None
+ -> import pdb; pdb.set_trace()
+ (Pdb) c
+ <BLANKLINE>
+ **********************************************************************
+ Can't use pdb.set_trace when running a layer as a subprocess!
+ **********************************************************************
+ <BLANKLINE>
+ --Return--
+ > testrunner-ex/sample2/sampletests_ntds.py(43)test_something3()->None
+ -> import pdb; pdb.set_trace()
+ (Pdb) c
+ <BLANKLINE>
+ **********************************************************************
+ Can't use pdb.set_trace when running a layer as a subprocess!
+ **********************************************************************
+ <BLANKLINE>
+ --Return--
+ > testrunner-ex/sample2/sampletests_ntds.py(46)test_something4()->None
+ -> import pdb; pdb.set_trace()
+ (Pdb) c
+ <BLANKLINE>
+ **********************************************************************
+ Can't use pdb.set_trace when running a layer as a subprocess!
+ **********************************************************************
+ <BLANKLINE>
+ --Return--
+ > testrunner-ex/sample2/sampletests_ntds.py(52)f()->None
+ -> import pdb; pdb.set_trace()
+ (Pdb) c
+ <BLANKLINE>
+ **********************************************************************
+ Can't use pdb.set_trace when running a layer as a subprocess!
+ **********************************************************************
+ <BLANKLINE>
+ --Return--
+ > doctest.py(351)set_trace()->None
+ -> pdb.Pdb.set_trace(self)
+ (Pdb) c
+ <BLANKLINE>
+ **********************************************************************
+ Can't use pdb.set_trace when running a layer as a subprocess!
+ **********************************************************************
+ <BLANKLINE>
+ --Return--
+ > doctest.py(351)set_trace()->None
+ -> pdb.Pdb.set_trace(self)
+ (Pdb) c
+ <BLANKLINE>
+ **********************************************************************
+ Can't use pdb.set_trace when running a layer as a subprocess!
+ **********************************************************************
+ <BLANKLINE>
+ Ran 7 tests with 0 failures and 0 errors in 0.008 seconds.
+ Tearing down left over layers:
+ Tear down sample2.sampletests_ntds.Layer ... not supported
+ Total: 8 tests, 0 failures, 0 errors
+
+If you want to use pdb from a test in a layer that is run as a
+subprocess, then rerun the test runner selecting *just* that layer so
+that it's not run as a subprocess.
More information about the Zope3-Checkins
mailing list