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

Skip to content

Commit d943fde

Browse files
committed
Run test_urllib2_localnet tests using unittest.main().
Capture threads in the setUpModule and cleanup threads in the tearDownModule.
1 parent 484f8a8 commit d943fde

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

Lib/test/test_urllib2_localnet.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
import http.server
66
import unittest
77
import hashlib
8+
89
from test import support
10+
911
threading = support.import_module('threading')
12+
1013
try:
1114
import ssl
1215
except ImportError:
@@ -57,14 +60,11 @@ def __init__(self, request_handler):
5760
request_handler.protocol_version = "HTTP/1.0"
5861
self.httpd = LoopbackHttpServer(("127.0.0.1", 0),
5962
request_handler)
60-
#print "Serving HTTP on %s port %s" % (self.httpd.server_name,
61-
# self.httpd.server_port)
6263
self.port = self.httpd.server_port
6364

6465
def stop(self):
6566
"""Stops the webserver if it's currently running."""
6667

67-
# Set the stop flag.
6868
self._stop_server = True
6969

7070
self.join()
@@ -232,6 +232,7 @@ def do_GET(self):
232232

233233
# Test cases
234234

235+
@unittest.skipUnless(threading, "Threading required for this test.")
235236
class ProxyAuthTests(unittest.TestCase):
236237
URL = "http://localhost"
237238

@@ -343,6 +344,7 @@ def log_message(self, *args):
343344
return FakeHTTPRequestHandler
344345

345346

347+
@unittest.skipUnless(threading, "Threading required for this test.")
346348
class TestUrlopen(unittest.TestCase):
347349
"""Tests urllib.request.urlopen using the network.
348350
@@ -590,9 +592,17 @@ def test_line_iteration(self):
590592
self.assertEqual(index + 1, len(lines))
591593

592594

593-
@support.reap_threads
594-
def test_main():
595-
support.run_unittest(ProxyAuthTests, TestUrlopen)
595+
threads_key = None
596+
597+
def setUpModule():
598+
# Store the threading_setup in a key and ensure that it is cleaned up
599+
# in the tearDown
600+
global threads_key
601+
threads_key = support.threading_setup()
602+
603+
def tearDownModule():
604+
if threads_key:
605+
support.threading_cleanup(threads_key)
596606

597607
if __name__ == "__main__":
598-
test_main()
608+
unittest.main()

0 commit comments

Comments
 (0)