Skip to content

Instantly share code, notes, and snippets.

@moylop260
Last active October 4, 2023 10:16
Show Gist options
  • Save moylop260/dd47889bdefc7379793222e6d39a170b to your computer and use it in GitHub Desktop.
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
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')
@h-stivalet
Copy link

This code is live saver. Thanks for sharing!

@luisiniguezh
Copy link

@moylop260 thanks, we were having a hard time with the tests, this helped us a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment