diff --git a/comtypes/test/test_dispinterface.py b/comtypes/test/test_dispinterface.py index 734020b5..5ef029eb 100644 --- a/comtypes/test/test_dispinterface.py +++ b/comtypes/test/test_dispinterface.py @@ -2,17 +2,23 @@ import unittest import comtypes.test.TestDispServer -from comtypes.server.register import register # , unregister +from comtypes.server.register import register, unregister def setUpModule(): - raise unittest.SkipTest( - "This test requires the tests to be run as admin since it tries to " - "register the test COM server. Is this a good idea?" - ) + try: + register(comtypes.test.TestDispServer.TestDispServer) + except WindowsError as e: + if e.winerror != 5: # [Error 5] Access is denied + raise e + raise unittest.SkipTest( + "This test requires the tests to be run as admin since it tries to " + "register the test COM server." + ) + - # If this test is ever NOT skipped, then this line needs to run. Keeping it here for posterity. - register(comtypes.test.TestDispServer.TestDispServer) +def tearDownModule(): + unregister(comtypes.test.TestDispServer.TestDispServer) @unittest.skip("This depends on 'pywin32'.")