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

Skip to content

Commit 3a03d2e

Browse files
committed
#17163: test_file now works with unittest test discovery. Patch by Zachary Ware.
1 parent a90b713 commit 3a03d2e

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

Lib/test/test_file.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from test.support import TESTFN, run_unittest
1111
from collections import UserList
1212

13-
class AutoFileTests(unittest.TestCase):
13+
class AutoFileTests:
1414
# file tests for which a test file is automatically set up
1515

1616
def setUp(self):
@@ -128,14 +128,14 @@ def testMethods(self):
128128
def testReadWhenWriting(self):
129129
self.assertRaises(IOError, self.f.read)
130130

131-
class CAutoFileTests(AutoFileTests):
131+
class CAutoFileTests(AutoFileTests, unittest.TestCase):
132132
open = io.open
133133

134-
class PyAutoFileTests(AutoFileTests):
134+
class PyAutoFileTests(AutoFileTests, unittest.TestCase):
135135
open = staticmethod(pyio.open)
136136

137137

138-
class OtherFileTests(unittest.TestCase):
138+
class OtherFileTests:
139139

140140
def testModeStrings(self):
141141
# check invalid mode strings
@@ -322,22 +322,18 @@ def testIteration(self):
322322
finally:
323323
os.unlink(TESTFN)
324324

325-
class COtherFileTests(OtherFileTests):
325+
class COtherFileTests(OtherFileTests, unittest.TestCase):
326326
open = io.open
327327

328-
class PyOtherFileTests(OtherFileTests):
328+
class PyOtherFileTests(OtherFileTests, unittest.TestCase):
329329
open = staticmethod(pyio.open)
330330

331331

332-
def test_main():
332+
def tearDownModule():
333333
# Historically, these tests have been sloppy about removing TESTFN.
334334
# So get rid of it no matter what.
335-
try:
336-
run_unittest(CAutoFileTests, PyAutoFileTests,
337-
COtherFileTests, PyOtherFileTests)
338-
finally:
339-
if os.path.exists(TESTFN):
340-
os.unlink(TESTFN)
335+
if os.path.exists(TESTFN):
336+
os.unlink(TESTFN)
341337

342338
if __name__ == '__main__':
343-
test_main()
339+
unittest.main()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,9 @@ Tests
605605

606606
- Issue #15539: Added regression tests for Tools/scripts/pindent.py.
607607

608+
- Issue #17163: test_file now works with unittest test discovery.
609+
Patch by Zachary Ware.
610+
608611
- Issue #16925: test_configparser now works with unittest test discovery.
609612
Patch by Zachary Ware.
610613

0 commit comments

Comments
 (0)