def test_it_works_with_the_simplest_test_items(ourtestdir):
ourtestdir.makepyfile(
conftest="""
import pytest
class MyCollector(pytest.Collector):
def __init__(self, fspath, items, **kwargs):
super(MyCollector, self).__init__(fspath, **kwargs)
self.items = items
def collect(self):
return self.items
class NoOpItem(pytest.Item):
def __init__(self, path, parent, module=None):
super(NoOpItem, self).__init__(path, parent)
if module is not None:
self.module = module
def runtest(self):
pass
def pytest_collect_file(path, parent):
if not str(path).endswith('.py'):
return
return MyCollector(
fspath=str(path),
items=[
NoOpItem(str(path), parent, 'foo'),
NoOpItem(str(path), parent),
],
parent=parent,
)
"""
)
args = ['-v']
out = ourtestdir.runpytest(*args)
out.assert_outcomes(passed=2)
评论列表
文章目录