Last active
October 4, 2023 10:16
-
-
Save moylop260/dd47889bdefc7379793222e6d39a170b to your computer and use it in GitHub Desktop.
How to skip a method test from a inherited test class for python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestCustom(Test): | |
def __init__(self, methodName='runTest'): | |
super(TestCustom, self).__init__(methodName) | |
# Skip original test from inherited class | |
custom_attributes = set(dir(TestCustom)) - set(dir(Test)) | |
custom_test_methods = [ | |
name for name in custom_attributes | |
if name.startswith('test_') and callable(getattr(self, name))] | |
if methodName not in custom_test_methods: | |
method = getattr(self, methodName) | |
method.__dict__['__unittest_skip__'] = True | |
method.__dict__['__unittest_skip_why__'] = ( | |
'Test executed from original module') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is live saver. Thanks for sharing!