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 zach.ware
Recipients brett.cannon, ezio.melotti, zach.ware
Date 2013-02-16.23:02:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1361055748.87.0.775684522637.issue17217@psf.upfronthosting.co.za>
In-reply-to
Content
test_format is an interesting case in the ongoing test discovery conversion.  It already uses unittest.main(), but still has test_main(), and discovery seems to work fine on Linux.  On Windows, however, test_format and test_non_ascii both fail with a UnicodeEncodeError.  Running under regrtest, this doesn't happen because of regrtest's replace_stdout() function.  Thus, running python -m test.test_format with the following patch works:

diff -r 168efd87e051 Lib/test/test_format.py
--- a/Lib/test/test_format.py   Fri Feb 15 23:38:23 2013 +0200
+++ b/Lib/test/test_format.py   Sat Feb 16 15:14:52 2013 -0600
@@ -325,9 +325,7 @@
         self.assertIs("{0:5s}".format(text), text)


-def test_main():
-    support.run_unittest(FormatTest)
-
-
 if __name__ == "__main__":
+    from test.regrtest import replace_stdout
+    replace_stdout()
     unittest.main()


Doing the same in a setUpModule function would work for both running the module and for a unittest discover command, but it would also cause replace_stdout() to be called twice when running under regrtest, which I don't think would be especially good.

The attached patch is one possible solution that I've come up with.  It moves replace_stdout from regrtest to support, and adds a "running_under_regrtest" flag to support that regrtest sets to True.  test_format then checks support.running_under_regrtest in setUpModule to determine whether to run support.replace_stdout.
History
Date User Action Args
2013-02-16 23:02:28zach.waresetrecipients: + zach.ware, brett.cannon, ezio.melotti
2013-02-16 23:02:28zach.waresetmessageid: <1361055748.87.0.775684522637.issue17217@psf.upfronthosting.co.za>
2013-02-16 23:02:28zach.warelinkissue17217 messages
2013-02-16 23:02:28zach.warecreate