test_it.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:pytest-randomly 作者: pytest-dev 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号