pytest-dependency
pytest-dependency copied to clipboard
Depends on all test methods in class
Is it possible to mark that test depends on all test methods inside specific test class?
This doesn't work
class TestABC:
def test_a(self):
pass
def test_b(self):
pass
@pytest.mark.dependency(depends=['TestABC'])
def test_depends_1():
pass # this test is skipped
@pytest.mark.dependency(depends=['TestABC::*'])
def test_depends_2():
pass # this test is skipped
Only this works for me
@pytest.mark.dependency(depends=[
'TestABC::test_a',
'TestABC::test_b',
])
def test_depends_3():
pass
Hi,
I'm also wondering if there is a possibility to mark an entire class as a dependency to avoid a long "dependency list".
EDIT: For now, I use a function to get a list of all test_* methods from a TestClass like
def get_class_methods(obj) -> list:
""""""
method_list = []
for attribute in dir(obj):
# Get value
attribute_value = getattr(obj, attribute)
# Check that it is callable
if callable(attribute_value):
# Filter dunder (__ prefix) method and check if it's a test_* method
if not attribute.startswith('__') and attribute.startswith('test_'):
method_list.append(obj.__name__ + '::' + attribute)
return method_list