This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients charlax, cjw296, docs@python, georg.brandl, terry.reedy, tim.peters
Date 2011-03-20.23:22:01
SpamBayes Score 1.9770697e-07
Marked as misclassified No
Message-id <1300663322.01.0.482248611546.issue3722@psf.upfronthosting.co.za>
In-reply-to
Content
You misunderstood my last response. The first paragraph *dismisses* the case of temporary print (raised by Charles-Axle) as out of scope for doctests and hence this issue. The next ones addresses *your* case of code *permanently* intended to print and raise and gives a workable solution to your example.

After failing to find a simpler example that works with 3.x*, I am now thinking of the following doc fix.

1. Add 'directly' before 'supported' in Tim's first sentence: "Examples containing both expected output and an exception are not supported." 

2. After the next sentence of explanation, add

"""Instead, try something like:

>>> def test():
...   print("hello")
...   raise IndexError()
...
>>> try:
...   test()
...   raise BaseException # Fail if no IndexError
... except IndexError:
...   pass
hello
"""

* I discovered a subtle consequence of the print change: "print 1, 1/0" will print '1' on a line by itself and then a traceback. "print(1,1/0)" just prints a traceback. Something like

class C():
    def __str__(self):
        raise IndexError
print(1, C(), sep='\n')

is required to print a value by itself on a line and then a traceback.
That is no simpler and probably less realistic than test() above.
History
Date User Action Args
2011-03-20 23:22:02terry.reedysetrecipients: + terry.reedy, tim.peters, georg.brandl, cjw296, charlax, docs@python
2011-03-20 23:22:02terry.reedysetmessageid: <1300663322.01.0.482248611546.issue3722@psf.upfronthosting.co.za>
2011-03-20 23:22:01terry.reedylinkissue3722 messages
2011-03-20 23:22:01terry.reedycreate