88# pylint: disable=invalid-name
99import logging
1010import os .path
11+ import unittest
1112
1213from click import testing
1314import mock
14- import testtools
1515
1616import SoftLayer
1717from SoftLayer .CLI import core
@@ -68,16 +68,15 @@ def _record_call(self, call):
6868 'offset' ]:
6969 details .append ('%s=%r' % (prop , getattr (call , prop )))
7070
71- logging .info ('%s::%s called; %s' ,
72- call .service , call .method , '; ' .join (details ))
71+ logging .info ('%s::%s called; %s' , call .service , call .method , '; ' .join (details ))
7372
7473
7574def _mock_key (service , method ):
7675 """Key to address a mock object in MockableTransport."""
7776 return '%s::%s' % (service , method )
7877
7978
80- class TestCase (testtools .TestCase ):
79+ class TestCase (unittest .TestCase ):
8180 """Testcase class with PEP-8 compatible method names."""
8281
8382 @classmethod
@@ -100,7 +99,7 @@ def tear_down(self):
10099 """Aliased from tearDown."""
101100
102101 def setUp (self ): # NOQA
103- testtools .TestCase .setUp (self )
102+ unittest .TestCase .setUp (self )
104103
105104 self .mocks .clear ()
106105
@@ -114,7 +113,7 @@ def setUp(self): # NOQA
114113 self .set_up ()
115114
116115 def tearDown (self ): # NOQA
117- testtools . TestCase .tearDown (self )
116+ super ( TestCase , self ) .tearDown ()
118117 self .tear_down ()
119118 self .mocks .clear ()
120119
@@ -141,8 +140,7 @@ def assert_called_with(self, service, method, **props):
141140 if self .calls (service , method , ** props ):
142141 return
143142
144- raise AssertionError ('%s::%s was not called with given properties: %s'
145- % (service , method , props ))
143+ raise AssertionError ('%s::%s was not called with given properties: %s' % (service , method , props ))
146144
147145 def assert_no_fail (self , result ):
148146 """Fail when a failing click result has an error"""
@@ -170,6 +168,17 @@ def run_command(self, args=None, env=None, fixtures=True, fmt='json', stdin=None
170168 runner = testing .CliRunner ()
171169 return runner .invoke (core .cli , args = args , input = stdin , obj = env or self .env )
172170
171+ def assertRaises (self , exception , function_callable , * args , ** kwds ): # pylint: disable=arguments-differ
172+ """Converts testtools.assertRaises to unittest.assertRaises calls.
173+
174+ testtools==2.4.0 require unittest2, which breaks pytest>=5.4.1 on skipTest.
175+ But switching to just using unittest breaks assertRaises because the format is slightly different.
176+ This basically just reformats the call so I don't have to re-write a bunch of tests.
177+ """
178+ with super (TestCase , self ).assertRaises (exception ) as cm :
179+ function_callable (* args , ** kwds )
180+ return cm .exception
181+
173182
174183def call_has_props (call , props ):
175184 """Check if a call has matching properties of a given props dictionary."""
0 commit comments