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

Skip to content

Commit d0dfe9a

Browse files
committed
#16852: test_genericpath, test_posixpath, test_ntpath, and test_macpath now work with unittest test discovery. Patch by Zachary Ware.
1 parent 0c270a8 commit d0dfe9a

5 files changed

Lines changed: 15 additions & 27 deletions

File tree

Lib/test/test_genericpath.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ def safe_rmdir(dirname):
1717
pass
1818

1919

20-
class GenericTest(unittest.TestCase):
21-
# The path module to be tested
22-
pathmodule = genericpath
20+
class GenericTest:
2321
common_attributes = ['commonprefix', 'getsize', 'getatime', 'getctime',
2422
'getmtime', 'exists', 'isdir', 'isfile']
2523
attributes = []
@@ -190,13 +188,16 @@ def test_isfile(self):
190188
support.unlink(support.TESTFN)
191189
safe_rmdir(support.TESTFN)
192190

191+
class TestGenericTest(GenericTest, unittest.TestCase):
192+
# Issue 16852: GenericTest can't inherit from unittest.TestCase
193+
# for test discovery purposes; CommonTest inherits from GenericTest
194+
# and is only meant to be inherited by others.
195+
pathmodule = genericpath
193196

194197
# Following TestCase is not supposed to be run from test_genericpath.
195198
# It is inherited by other test modules (macpath, ntpath, posixpath).
196199

197200
class CommonTest(GenericTest):
198-
# The path module to be tested
199-
pathmodule = None
200201
common_attributes = GenericTest.common_attributes + [
201202
# Properties
202203
'curdir', 'pardir', 'extsep', 'sep',
@@ -328,9 +329,5 @@ def test_nonascii_abspath(self):
328329
self.test_abspath()
329330

330331

331-
def test_main():
332-
support.run_unittest(GenericTest)
333-
334-
335332
if __name__=="__main__":
336-
test_main()
333+
unittest.main()

Lib/test/test_macpath.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,9 @@ def test_normpath(self):
115115
self.assertEqual(normpath(b"a:b:"), b"a:b")
116116

117117

118-
class MacCommonTest(test_genericpath.CommonTest):
118+
class MacCommonTest(test_genericpath.CommonTest, unittest.TestCase):
119119
pathmodule = macpath
120120

121121

122-
def test_main():
123-
support.run_unittest(MacPathTestCase, MacCommonTest)
124-
125-
126122
if __name__ == "__main__":
127-
test_main()
123+
unittest.main()

Lib/test/test_ntpath.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,10 @@ def test_sameopenfile(self):
257257
ntpath.sameopenfile(-1, -1)
258258

259259

260-
class NtCommonTest(test_genericpath.CommonTest):
260+
class NtCommonTest(test_genericpath.CommonTest, unittest.TestCase):
261261
pathmodule = ntpath
262262
attributes = ['relpath', 'splitunc']
263263

264264

265-
def test_main():
266-
support.run_unittest(TestNtpath, NtCommonTest)
267-
268-
269265
if __name__ == "__main__":
270266
unittest.main()

Lib/test/test_posixpath.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,10 @@ def test_sameopenfile(self):
524524
self.assertTrue(posixpath.sameopenfile(a.fileno(), b.fileno()))
525525

526526

527-
class PosixCommonTest(test_genericpath.CommonTest):
527+
class PosixCommonTest(test_genericpath.CommonTest, unittest.TestCase):
528528
pathmodule = posixpath
529529
attributes = ['relpath', 'samefile', 'sameopenfile', 'samestat']
530530

531531

532-
def test_main():
533-
support.run_unittest(PosixPathTest, PosixCommonTest)
534-
535-
536532
if __name__=="__main__":
537-
test_main()
533+
unittest.main()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ Library
408408
Tests
409409
-----
410410

411+
- Issue #16852: test_genericpath, test_posixpath, test_ntpath, and test_macpath
412+
now work with unittest test discovery. Patch by Zachary Ware.
413+
411414
- Issue #16748: test_heapq now works with unittest test discovery.
412415

413416
- Issue #15324: Fix regrtest parsing of --fromfile, --match, and --randomize

0 commit comments

Comments
 (0)