python: remove the Instance collector node
This commit is contained in:
@@ -12,7 +12,7 @@ from _pytest.monkeypatch import MonkeyPatch
|
||||
from _pytest.nodes import Collector
|
||||
from _pytest.pytester import Pytester
|
||||
from _pytest.python import Class
|
||||
from _pytest.python import Instance
|
||||
from _pytest.python import Function
|
||||
|
||||
|
||||
class TestModule:
|
||||
@@ -585,7 +585,7 @@ class TestFunction:
|
||||
pass
|
||||
"""
|
||||
)
|
||||
colitems = modcol.collect()[0].collect()[0].collect()
|
||||
colitems = modcol.collect()[0].collect()
|
||||
assert colitems[0].name == "test1[a-c]"
|
||||
assert colitems[1].name == "test1[b-c]"
|
||||
assert colitems[2].name == "test2[a-c]"
|
||||
@@ -1183,19 +1183,26 @@ class TestReportInfo:
|
||||
modcol = pytester.getmodulecol(
|
||||
"""
|
||||
# lineno 0
|
||||
class TestClass(object):
|
||||
class TestClass:
|
||||
def __getattr__(self, name):
|
||||
return "this is not an int"
|
||||
|
||||
def __class_getattr__(cls, name):
|
||||
return "this is not an int"
|
||||
|
||||
def intest_foo(self):
|
||||
pass
|
||||
|
||||
def test_bar(self):
|
||||
pass
|
||||
"""
|
||||
)
|
||||
classcol = pytester.collect_by_name(modcol, "TestClass")
|
||||
assert isinstance(classcol, Class)
|
||||
instance = list(classcol.collect())[0]
|
||||
assert isinstance(instance, Instance)
|
||||
path, lineno, msg = instance.reportinfo()
|
||||
path, lineno, msg = classcol.reportinfo()
|
||||
func = list(classcol.collect())[0]
|
||||
assert isinstance(func, Function)
|
||||
path, lineno, msg = func.reportinfo()
|
||||
|
||||
|
||||
def test_customized_python_discovery(pytester: Pytester) -> None:
|
||||
|
||||
@@ -5,6 +5,7 @@ from _pytest import runner
|
||||
from _pytest._code import getfslineno
|
||||
from _pytest.fixtures import getfixturemarker
|
||||
from _pytest.pytester import Pytester
|
||||
from _pytest.python import Function
|
||||
|
||||
|
||||
class TestOEJSKITSpecials:
|
||||
@@ -475,3 +476,28 @@ class TestParameterize:
|
||||
)
|
||||
res = pytester.runpytest("--collect-only")
|
||||
res.stdout.fnmatch_lines(["*spam-2*", "*ham-2*"])
|
||||
|
||||
|
||||
def test_function_instance(pytester: Pytester) -> None:
|
||||
items = pytester.getitems(
|
||||
"""
|
||||
def test_func(): pass
|
||||
class TestIt:
|
||||
def test_method(self): pass
|
||||
@classmethod
|
||||
def test_class(cls): pass
|
||||
@staticmethod
|
||||
def test_static(): pass
|
||||
"""
|
||||
)
|
||||
assert len(items) == 3
|
||||
assert isinstance(items[0], Function)
|
||||
assert items[0].name == "test_func"
|
||||
assert items[0].instance is None
|
||||
assert isinstance(items[1], Function)
|
||||
assert items[1].name == "test_method"
|
||||
assert items[1].instance is not None
|
||||
assert items[1].instance.__class__.__name__ == "TestIt"
|
||||
assert isinstance(items[2], Function)
|
||||
assert items[2].name == "test_static"
|
||||
assert items[2].instance is None
|
||||
|
||||
Reference in New Issue
Block a user