fix classmethod not being discovered and add unit-test
This commit is contained in:
parent
fd30759d94
commit
e56898029b
|
@ -403,7 +403,7 @@ class PyCollector(PyobjMixin, nodes.Collector):
|
|||
|
||||
def istestfunction(self, obj: object, name: str) -> bool:
|
||||
if self.funcnamefilter(name) or self.isnosetest(obj):
|
||||
if isinstance(obj, staticmethod):
|
||||
if isinstance(obj, staticmethod) or isinstance(obj, classmethod):
|
||||
# staticmethods need to be unwrapped.
|
||||
obj = safe_getattr(obj, "__func__", False)
|
||||
return callable(obj) and fixtures.getfixturemarker(obj) is None
|
||||
|
|
|
@ -735,6 +735,20 @@ class Test_genitems:
|
|||
assert s.endswith("test_example_items1.testone")
|
||||
print(s)
|
||||
|
||||
def test_classmethod_is_discovered(self, pytester: Pytester) -> None:
|
||||
"""Test that classmethods are discovered"""
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
class TestCase:
|
||||
@classmethod
|
||||
def test_classmethod(cls) -> None:
|
||||
pass
|
||||
"""
|
||||
)
|
||||
items, reprec = pytester.inline_genitems(p)
|
||||
ids = [x.getmodpath() for x in items] # type: ignore[attr-defined]
|
||||
assert ids == ["TestCase.test_classmethod"]
|
||||
|
||||
def test_class_and_functions_discovery_using_glob(self, pytester: Pytester) -> None:
|
||||
"""Test that Python_classes and Python_functions config options work
|
||||
as prefixes and glob-like patterns (#600)."""
|
||||
|
|
Loading…
Reference in New Issue