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
This commit is contained in:
parent
dd3bc8fe61
commit
511ac2ee60
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user