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

Skip to content

Commit 3e9a9ae

Browse files
committed
Update various test modules to use unittest.main() for test discovery
instead of manually listing tests for test.support.run_unittest().
1 parent e382b58 commit 3e9a9ae

18 files changed

Lines changed: 24 additions & 108 deletions

Lib/test/test_ast.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -951,9 +951,6 @@ def test_stdlib_validates(self):
951951
compile(mod, fn, "exec")
952952

953953

954-
def test_main():
955-
support.run_unittest(AST_Tests, ASTHelpers_Test, ASTValidatorTests)
956-
957954
def main():
958955
if __name__ != '__main__':
959956
return
@@ -966,7 +963,7 @@ def main():
966963
print("]")
967964
print("main()")
968965
raise SystemExit
969-
test_main()
966+
unittest.main()
970967

971968
#### EVERYTHING BELOW IS GENERATED #####
972969
exec_results = [

Lib/test/test_asynchat.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,5 @@ def test_given_list(self):
283283
self.assertEqual(f.pop(), (0, None))
284284

285285

286-
def test_main(verbose=None):
287-
support.run_unittest(TestAsynchat, TestAsynchat_WithPoll,
288-
TestHelperFunctions, TestFifo)
289-
290286
if __name__ == "__main__":
291-
test_main(verbose=True)
287+
unittest.main()

Lib/test/test_buffer.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4283,9 +4283,5 @@ def test_issue_7385(self):
42834283
self.assertRaises(BufferError, memoryview, x)
42844284

42854285

4286-
def test_main():
4287-
support.run_unittest(TestBufferProtocol)
4288-
4289-
42904286
if __name__ == "__main__":
4291-
test_main()
4287+
unittest.main()

Lib/test/test_codeccallbacks.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,6 @@ def mutating(exc):
875875
with self.assertRaises(TypeError):
876876
data.decode(encoding, "test.replacing")
877877

878-
def test_main():
879-
test.support.run_unittest(CodecCallbackTest)
880878

881879
if __name__ == "__main__":
882-
test_main()
880+
unittest.main()

Lib/test/test_contextlib.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,5 @@ def test_exception_hierarchy(self):
617617
'Hello'[50]
618618

619619

620-
# This is needed to make the test actually run under regrtest.py!
621-
def test_main():
622-
support.run_unittest(__name__)
623-
624620
if __name__ == "__main__":
625-
test_main()
621+
unittest.main()

Lib/test/test_faulthandler.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,5 @@ def test_register_chain(self):
588588
self.check_register(chain=True)
589589

590590

591-
def test_main():
592-
support.run_unittest(FaultHandlerTests)
593-
594591
if __name__ == "__main__":
595-
test_main()
592+
unittest.main()

Lib/test/test_fileinput.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -835,22 +835,6 @@ def test(self):
835835
self.assertIs(kwargs.pop('encoding'), encoding)
836836
self.assertFalse(kwargs)
837837

838-
def test_main():
839-
run_unittest(
840-
BufferSizesTests,
841-
FileInputTests,
842-
Test_fileinput_input,
843-
Test_fileinput_close,
844-
Test_fileinput_nextfile,
845-
Test_fileinput_filename,
846-
Test_fileinput_lineno,
847-
Test_fileinput_filelineno,
848-
Test_fileinput_fileno,
849-
Test_fileinput_isfirstline,
850-
Test_fileinput_isstdin,
851-
Test_hook_compressed,
852-
Test_hook_encoded,
853-
)
854838

855839
if __name__ == "__main__":
856-
test_main()
840+
unittest.main()

Lib/test/test_frozen.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ def test_frozen(self):
7272
del sys.modules['__phello__']
7373
del sys.modules['__phello__.spam']
7474

75-
def test_main():
76-
run_unittest(FrozenTests)
7775

7876
if __name__ == "__main__":
79-
test_main()
77+
unittest.main()

Lib/test/test_getargs2.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import unittest
22
from test import support
33
from _testcapi import getargs_keywords, getargs_keyword_only
4+
try:
5+
from _testcapi import getargs_L, getargs_K
6+
except ImportError:
7+
getargs_L = None # PY_LONG_LONG not available
48

59
# > How about the following counterproposal. This also changes some of
610
# > the other format codes to be a little more regular.
@@ -182,6 +186,7 @@ def test_n(self):
182186
self.assertRaises(OverflowError, getargs_n, VERY_LARGE)
183187

184188

189+
@unittest.skipIf(getargs_L is None, 'PY_LONG_LONG is not available')
185190
class LongLong_TestCase(unittest.TestCase):
186191
def test_L(self):
187192
from _testcapi import getargs_L
@@ -534,24 +539,5 @@ def test_Z_hash(self):
534539
self.assertIsNone(getargs_Z_hash(None))
535540

536541

537-
def test_main():
538-
tests = [
539-
Signed_TestCase,
540-
Unsigned_TestCase,
541-
Boolean_TestCase,
542-
Tuple_TestCase,
543-
Keywords_TestCase,
544-
KeywordOnly_TestCase,
545-
Bytes_TestCase,
546-
Unicode_TestCase,
547-
]
548-
try:
549-
from _testcapi import getargs_L, getargs_K
550-
except ImportError:
551-
pass # PY_LONG_LONG not available
552-
else:
553-
tests.append(LongLong_TestCase)
554-
support.run_unittest(*tests)
555-
556542
if __name__ == "__main__":
557-
test_main()
543+
unittest.main()

Lib/test/test_hashlib.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,6 @@ def hash_in_chunks(chunk_size, event):
494494

495495
self.assertEqual(expected_hash, hasher.hexdigest())
496496

497-
def test_main():
498-
support.run_unittest(HashLibTestCase)
499497

500498
if __name__ == "__main__":
501-
test_main()
499+
unittest.main()

0 commit comments

Comments
 (0)