From 511ac2ee604ccf14f0c7f8db7ab7b7d5e250310f Mon Sep 17 00:00:00 2001 From: Alistair Coles Date: Thu, 4 May 2017 12:47:17 +0100 Subject: [PATCH] Use setUpModule instead of setup for module level unit test setup Module setup() and teardown() functions are found by nosetests [1] but unittests expects setUpModule() and tearDownModule() [2]. The latter function names are also found by nosetests, so using those function names enables the test module to be run with either nosetests or unittest. Although the tox test envs and .unittests script use nosetests, this change allows the convenience of using unittest, for example when it is the default test runner in a development environment such as PyCharm. This change also makes it unnecessary to explicitly call the setup() and teardown() functions when executing the module directly. [1] http://nose.readthedocs.io/en/latest/writing_tests.html#test-modules [2] https://docs.python.org/2/library/unittest.html#setupmodule-and-teardownmodule Change-Id: Ib2e5470a339af1f937b25d643b64356e8848ed36 --- test/unit/proxy/test_mem_server.py | 13 ++++++------- test/unit/proxy/test_server.py | 10 +++------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/test/unit/proxy/test_mem_server.py b/test/unit/proxy/test_mem_server.py index 336b98b766..0901091529 100644 --- a/test/unit/proxy/test_mem_server.py +++ b/test/unit/proxy/test_mem_server.py @@ -16,15 +16,18 @@ import unittest from test.unit.proxy import test_server -from test.unit.proxy.test_server import teardown from swift.obj import mem_server -def setup(): +def setUpModule(): test_server.do_setup(mem_server) +def tearDownModule(): + test_server.tearDownModule() + + class TestController(test_server.TestController): pass @@ -72,8 +75,4 @@ class TestAccountControllerFakeGetResponse( if __name__ == '__main__': - setup() - try: - unittest.main() - finally: - teardown() + unittest.main() diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index f7211763c0..a7164e646d 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -118,11 +118,11 @@ def unpatch_policies(f): return wrapper -def setup(): +def setUpModule(): do_setup(object_server) -def teardown(): +def tearDownModule(): teardown_servers(_test_context) @@ -9243,8 +9243,4 @@ class TestSocketObjectVersions(unittest.TestCase): if __name__ == '__main__': - setup() - try: - unittest.main() - finally: - teardown() + unittest.main()