Skip to content

Commit 1ef62ab

Browse files
pquentinsethmlarson
authored andcommitted
Stop using unittest (urllib3#1649)
1 parent 2c055b4 commit 1ef62ab

File tree

12 files changed

+35
-51
lines changed

12 files changed

+35
-51
lines changed

dev-requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ wheel==0.30.0
55
tornado==5.1.1
66
PySocks==1.6.8
77
pkginfo==1.4.2
8-
pytest-timeout==1.3.1
9-
pytest==4.0.0
10-
pluggy==0.11.0
8+
pytest-timeout==1.3.3
9+
pytest==4.6.4
1110

1211
# https://github.com/ionelmc/python-lazy-object-proxy/issues/30
1312
lazy-object-proxy==1.4.0

dummyserver/testcase.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import threading
2-
import unittest
32

43
import pytest
54
from tornado import ioloop, web
@@ -20,7 +19,7 @@ def consume_socket(sock, chunks=65536):
2019
pass
2120

2221

23-
class SocketDummyServerTestCase(unittest.TestCase):
22+
class SocketDummyServerTestCase(object):
2423
"""
2524
A simple socket-based server is created for this class that is good for
2625
exactly one request.
@@ -67,7 +66,7 @@ def start_basic_handler(cls, **kw):
6766
)
6867

6968
@classmethod
70-
def tearDownClass(cls):
69+
def teardown_class(cls):
7170
if hasattr(cls, "server_thread"):
7271
cls.server_thread.join(0.1)
7372

@@ -101,10 +100,10 @@ def _start_server(cls, socket_handler):
101100
cls.port = cls.server_thread.port
102101

103102

104-
class HTTPDummyServerTestCase(unittest.TestCase):
103+
class HTTPDummyServerTestCase(object):
105104
""" A simple HTTP server that runs when your test class runs
106105
107-
Have your unittest class inherit from this one, and then a simple server
106+
Have your test class inherit from this one, and then a simple server
108107
will start when your tests run, and automatically shut down when they
109108
complete. For examples of what test requests you can send to the server,
110109
see the TestingApp in dummyserver/handlers.py.
@@ -131,11 +130,11 @@ def _stop_server(cls):
131130
cls.server_thread.join()
132131

133132
@classmethod
134-
def setUpClass(cls):
133+
def setup_class(cls):
135134
cls._start_server()
136135

137136
@classmethod
138-
def tearDownClass(cls):
137+
def teardown_class(cls):
139138
cls._stop_server()
140139

141140

@@ -150,7 +149,7 @@ class IPV6HTTPSDummyServerTestCase(HTTPSDummyServerTestCase):
150149
host = "::1"
151150

152151

153-
class HTTPDummyProxyTestCase(unittest.TestCase):
152+
class HTTPDummyProxyTestCase(object):
154153

155154
http_host = "localhost"
156155
http_host_alt = "127.0.0.1"
@@ -163,7 +162,7 @@ class HTTPDummyProxyTestCase(unittest.TestCase):
163162
proxy_host_alt = "127.0.0.1"
164163

165164
@classmethod
166-
def setUpClass(cls):
165+
def setup_class(cls):
167166
cls.io_loop = ioloop.IOLoop.current()
168167

169168
app = web.Application([(r".*", TestingApp)])
@@ -184,7 +183,7 @@ def setUpClass(cls):
184183
cls.server_thread = run_loop_in_thread(cls.io_loop)
185184

186185
@classmethod
187-
def tearDownClass(cls):
186+
def teardown_class(cls):
188187
cls.io_loop.add_callback(cls.http_server.stop)
189188
cls.io_loop.add_callback(cls.https_server.stop)
190189
cls.io_loop.add_callback(cls.proxy_server.stop)

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ requires-dist =
2323

2424
[tool:pytest]
2525
xfail_strict = true
26+
python_classes = Test *TestCase

test/appengine/test_gae_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _absolute_url(self, path):
3737
# that URLFetch is used by the connection manager.
3838
@pytest.mark.usefixtures("testbed")
3939
class TestGAEConnectionManager(test_connectionpool.TestConnectionPool):
40-
def setUp(self):
40+
def setup_method(self, method):
4141
self.manager = appengine.AppEngineManager()
4242
self.pool = MockPool(self.host, self.port, self.manager)
4343

@@ -105,7 +105,7 @@ def test_exceptions(self):
105105

106106
@pytest.mark.usefixtures("testbed")
107107
class TestGAEConnectionManagerWithSSL(dummyserver.testcase.HTTPSDummyServerTestCase):
108-
def setUp(self):
108+
def setup_method(self, method):
109109
self.manager = appengine.AppEngineManager()
110110
self.pool = MockPool(self.host, self.port, self.manager, "https")
111111

@@ -119,7 +119,7 @@ def test_exceptions(self):
119119

120120
@pytest.mark.usefixtures("testbed")
121121
class TestGAERetry(test_connectionpool.TestRetry):
122-
def setUp(self):
122+
def setup_method(self, method):
123123
self.manager = appengine.AppEngineManager()
124124
self.pool = MockPool(self.host, self.port, self.manager)
125125

@@ -159,7 +159,7 @@ def test_retry_return_in_response(self):
159159

160160
@pytest.mark.usefixtures("testbed")
161161
class TestGAERetryAfter(test_connectionpool.TestRetryAfter):
162-
def setUp(self):
162+
def setup_method(self, method):
163163
# Disable urlfetch which doesn't respect Retry-After header.
164164
self.manager = appengine.AppEngineManager(urlfetch_retries=False)
165165
self.pool = MockPool(self.host, self.port, self.manager)

test/appengine/test_urlfetch.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import httplib
66
import StringIO
7-
import unittest
87

98
from mock import patch
109
import pytest
@@ -45,7 +44,7 @@ def test_urlfetch_called_with_http(self):
4544

4645

4746
@pytest.mark.usefixtures("sandbox")
48-
class TestHTTPS(unittest.TestCase):
47+
class TestHTTPS(object):
4948
@pytest.mark.xfail(
5049
reason="This is not yet supported by urlfetch, presence of the ssl "
5150
"module will bypass urlfetch."

test/contrib/test_pyopenssl.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22
import os
3-
import unittest
43

54
import mock
65
import pytest
@@ -49,7 +48,7 @@ def teardown_module():
4948
)
5049

5150

52-
class TestPyOpenSSLHelpers(unittest.TestCase):
51+
class TestPyOpenSSLHelpers(object):
5352
"""
5453
Tests for PyOpenSSL helper functions.
5554
"""

test/contrib/test_pyopenssl_dependencies.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
import unittest
32
import pytest
43

54
from mock import patch, Mock
@@ -28,7 +27,7 @@ def teardown_module():
2827
pass
2928

3029

31-
class TestPyOpenSSLInjection(unittest.TestCase):
30+
class TestPyOpenSSLInjection(object):
3231
"""
3332
Tests for error handling in pyopenssl's 'inject_into urllib3'
3433
"""

test/test_no_ssl.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"""
77

88
import sys
9-
import unittest
109
import pytest
1110

1211

@@ -64,15 +63,16 @@ def pop(self):
6463
module_stash = ModuleStash("urllib3")
6564

6665

67-
class TestWithoutSSL(unittest.TestCase):
68-
def setUp(self):
66+
class TestWithoutSSL(object):
67+
@classmethod
68+
def setup_class(self):
6969
sys.modules.pop("ssl", None)
7070
sys.modules.pop("_ssl", None)
7171

7272
module_stash.stash()
7373
sys.meta_path.insert(0, ssl_blocker)
7474

75-
def tearDown(self):
75+
def teardown_class(self):
7676
sys.meta_path.remove(ssl_blocker)
7777
module_stash.pop()
7878

test/with_dummyserver/test_connectionpool.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import logging
33
import socket
44
import sys
5-
import unittest
65
import time
76
import warnings
87
import pytest
@@ -1159,7 +1158,3 @@ def test_pool_size_redirect(self):
11591158
) as pool:
11601159
pool.urlopen("GET", "/redirect", preload_content=False)
11611160
assert pool.num_connections == 1
1162-
1163-
1164-
if __name__ == "__main__":
1165-
unittest.main()

test/with_dummyserver/test_https.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44
import ssl
55
import sys
6-
import unittest
76
import warnings
87

98
import mock
@@ -784,7 +783,3 @@ def test_can_validate_ipv6_san(self):
784783
) as https_pool:
785784
r = https_pool.request("GET", "/")
786785
assert r.status == 200
787-
788-
789-
if __name__ == "__main__":
790-
unittest.main()

0 commit comments

Comments
 (0)