New submission from Zachary Ware: 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. ---------- components: Tests files: test_format_discovery.diff keywords: patch messages: 182248 nosy: brett.cannon, ezio.melotti, zach.ware priority: normal severity: normal status: open title: Fix test discovery for test_format.py on Windows type: behavior versions: Python 3.3, Python 3.4 Added file: http://bugs.python.org/file29093/test_format_discovery.diff _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue17217> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com