|
5 | 5 | import http.server |
6 | 6 | import unittest |
7 | 7 | import hashlib |
| 8 | + |
8 | 9 | from test import support |
| 10 | + |
9 | 11 | threading = support.import_module('threading') |
| 12 | + |
10 | 13 | try: |
11 | 14 | import ssl |
12 | 15 | except ImportError: |
@@ -57,14 +60,11 @@ def __init__(self, request_handler): |
57 | 60 | request_handler.protocol_version = "HTTP/1.0" |
58 | 61 | self.httpd = LoopbackHttpServer(("127.0.0.1", 0), |
59 | 62 | request_handler) |
60 | | - #print "Serving HTTP on %s port %s" % (self.httpd.server_name, |
61 | | - # self.httpd.server_port) |
62 | 63 | self.port = self.httpd.server_port |
63 | 64 |
|
64 | 65 | def stop(self): |
65 | 66 | """Stops the webserver if it's currently running.""" |
66 | 67 |
|
67 | | - # Set the stop flag. |
68 | 68 | self._stop_server = True |
69 | 69 |
|
70 | 70 | self.join() |
@@ -232,6 +232,7 @@ def do_GET(self): |
232 | 232 |
|
233 | 233 | # Test cases |
234 | 234 |
|
| 235 | +@unittest.skipUnless(threading, "Threading required for this test.") |
235 | 236 | class ProxyAuthTests(unittest.TestCase): |
236 | 237 | URL = "http://localhost" |
237 | 238 |
|
@@ -343,6 +344,7 @@ def log_message(self, *args): |
343 | 344 | return FakeHTTPRequestHandler |
344 | 345 |
|
345 | 346 |
|
| 347 | +@unittest.skipUnless(threading, "Threading required for this test.") |
346 | 348 | class TestUrlopen(unittest.TestCase): |
347 | 349 | """Tests urllib.request.urlopen using the network. |
348 | 350 |
|
@@ -590,9 +592,17 @@ def test_line_iteration(self): |
590 | 592 | self.assertEqual(index + 1, len(lines)) |
591 | 593 |
|
592 | 594 |
|
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) |
596 | 606 |
|
597 | 607 | if __name__ == "__main__": |
598 | | - test_main() |
| 608 | + unittest.main() |
0 commit comments