Allow unit tests to be run via pytest

You can run all tests by just running

   $ pytest

Or just unit tests with

   $ pytest test/unit/

Or one specific test with

   $ pytest test/unit/test_swiftclient.py::TestConnection::test_reauth

Change-Id: I1dfa239f9ee9ea85663b5c1f22631a97f87b4dfc
This commit is contained in:
Tim Burke
2021-05-10 22:51:22 -07:00
parent 38c435f888
commit 99b5b81217

View File

@@ -28,7 +28,6 @@ import textwrap
from time import localtime, mktime, strftime, strptime from time import localtime, mktime, strftime, strptime
import six import six
import sys
import swiftclient import swiftclient
from swiftclient.service import SwiftError from swiftclient.service import SwiftError
@@ -1155,9 +1154,12 @@ class TestShell(unittest.TestCase):
'x-object-meta-mtime': mock.ANY}, 'x-object-meta-mtime': mock.ANY},
response_dict={}) response_dict={})
@mock.patch('swiftclient.shell.stdin')
@mock.patch('swiftclient.shell.io.open') @mock.patch('swiftclient.shell.io.open')
@mock.patch('swiftclient.service.SwiftService.upload') @mock.patch('swiftclient.service.SwiftService.upload')
def test_upload_from_stdin(self, upload_mock, io_open_mock): def test_upload_from_stdin(self, upload_mock, io_open_mock, stdin_mock):
stdin_mock.fileno.return_value = 123
def fake_open(fd, mode): def fake_open(fd, mode):
mock_io = mock.Mock() mock_io = mock.Mock()
mock_io.fileno.return_value = fd mock_io.fileno.return_value = fd
@@ -1173,8 +1175,8 @@ class TestShell(unittest.TestCase):
# element. This is because the upload method takes a container and a # element. This is because the upload method takes a container and a
# list of SwiftUploadObjects. # list of SwiftUploadObjects.
swift_upload_obj = upload_mock.mock_calls[0][1][1][0] swift_upload_obj = upload_mock.mock_calls[0][1][1][0]
self.assertEqual(sys.stdin.fileno(), swift_upload_obj.source.fileno()) self.assertEqual(123, swift_upload_obj.source.fileno())
io_open_mock.assert_called_once_with(sys.stdin.fileno(), mode='rb') io_open_mock.assert_called_once_with(123, mode='rb')
@mock.patch('swiftclient.service.SwiftService.upload') @mock.patch('swiftclient.service.SwiftService.upload')
def test_upload_from_stdin_no_name(self, upload_mock): def test_upload_from_stdin_no_name(self, upload_mock):
@@ -3015,6 +3017,10 @@ class TestKeystoneOptions(MockHttpTest):
no_auth=no_auth) no_auth=no_auth)
def test_all_args_passed_to_keystone(self): def test_all_args_passed_to_keystone(self):
rootLogger = logging.getLogger()
orig_lvl = rootLogger.getEffectiveLevel()
try:
rootLogger.setLevel(logging.DEBUG)
# check that all possible command line args are passed to keystone # check that all possible command line args are passed to keystone
opts = {'auth-version': '3'} opts = {'auth-version': '3'}
os_opts = dict(self.all_os_opts) os_opts = dict(self.all_os_opts)
@@ -3033,6 +3039,8 @@ class TestKeystoneOptions(MockHttpTest):
os_opts.pop(o) os_opts.pop(o)
self.defaults['auth-version'] = '2.0' self.defaults['auth-version'] = '2.0'
self._test_options(opts, os_opts, flags=self.flags) self._test_options(opts, os_opts, flags=self.flags)
finally:
rootLogger.setLevel(orig_lvl)
def test_catalog_options_and_flags_not_required_v3(self): def test_catalog_options_and_flags_not_required_v3(self):
# check that all possible command line args are passed to keystone # check that all possible command line args are passed to keystone