python类mark()的实例源码

mark.py 文件源码 项目:godot-python 作者: touilleMan 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def pytest_configure(config):
    import pytest
    if config.option.strict:
        pytest.mark._config = config
mark.py 文件源码 项目:godot-python 作者: touilleMan 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __call__(self, *args, **kwargs):
        """ if passed a single callable argument: decorate it with mark info.
            otherwise add *args/**kwargs in-place to mark information. """
        if args and not kwargs:
            func = args[0]
            is_class = inspect.isclass(func)
            if len(args) == 1 and (istestfunc(func) or is_class):
                if is_class:
                    if hasattr(func, 'pytestmark'):
                        mark_list = func.pytestmark
                        if not isinstance(mark_list, list):
                            mark_list = [mark_list]
                        # always work on a copy to avoid updating pytestmark
                        # from a superclass by accident
                        mark_list = mark_list + [self]
                        func.pytestmark = mark_list
                    else:
                        func.pytestmark = [self]
                else:
                    holder = getattr(func, self.name, None)
                    if holder is None:
                        holder = MarkInfo(
                            self.name, self.args, self.kwargs
                        )
                        setattr(func, self.name, holder)
                    else:
                        holder.add(self.args, self.kwargs)
                return func
        kw = self.kwargs.copy()
        kw.update(kwargs)
        args = self.args + args
        return self.__class__(self.name, args=args, kwargs=kw)
mark.py 文件源码 项目:godot-python 作者: touilleMan 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def pytest_namespace():
    return {'mark': MarkGenerator()}
mark.py 文件源码 项目:godot-python 作者: touilleMan 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def pytest_addoption(parser):
    group = parser.getgroup("general")
    group._addoption(
        '-k',
        action="store", dest="keyword", default='', metavar="EXPRESSION",
        help="only run tests which match the given substring expression. "
             "An expression is a python evaluatable expression "
             "where all names are substring-matched against test names "
             "and their parent classes. Example: -k 'test_method or test_"
             "other' matches all test functions and classes whose name "
             "contains 'test_method' or 'test_other'. "
             "Additionally keywords are matched to classes and functions "
             "containing extra names in their 'extra_keyword_matches' set, "
             "as well as functions which have names assigned directly to them."
    )

    group._addoption(
        "-m",
        action="store", dest="markexpr", default="", metavar="MARKEXPR",
        help="only run tests matching given mark expression.  "
             "example: -m 'mark1 and not mark2'."
    )

    group.addoption(
        "--markers", action="store_true",
        help="show markers (builtin, plugin and per-project ones)."
    )

    parser.addini("markers", "markers for test functions", 'linelist')
mark.py 文件源码 项目:godot-python 作者: touilleMan 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def pytest_cmdline_main(config):
    import _pytest.config
    if config.option.markers:
        config._do_configure()
        tw = _pytest.config.create_terminal_writer(config)
        for line in config.getini("markers"):
            name, rest = line.split(":", 1)
            tw.write("@pytest.mark.%s:" % name, bold=True)
            tw.line(rest)
            tw.line()
        config._ensure_unconfigure()
        return 0
mark.py 文件源码 项目:godot-python 作者: touilleMan 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def pytest_configure(config):
    import pytest
    if config.option.strict:
        pytest.mark._config = config
mark.py 文件源码 项目:godot-python 作者: touilleMan 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __call__(self, *args, **kwargs):
        """ if passed a single callable argument: decorate it with mark info.
            otherwise add *args/**kwargs in-place to mark information. """
        if args and not kwargs:
            func = args[0]
            is_class = inspect.isclass(func)
            if len(args) == 1 and (istestfunc(func) or is_class):
                if is_class:
                    if hasattr(func, 'pytestmark'):
                        mark_list = func.pytestmark
                        if not isinstance(mark_list, list):
                            mark_list = [mark_list]
                        # always work on a copy to avoid updating pytestmark
                        # from a superclass by accident
                        mark_list = mark_list + [self]
                        func.pytestmark = mark_list
                    else:
                        func.pytestmark = [self]
                else:
                    holder = getattr(func, self.name, None)
                    if holder is None:
                        holder = MarkInfo(
                            self.name, self.args, self.kwargs
                        )
                        setattr(func, self.name, holder)
                    else:
                        holder.add(self.args, self.kwargs)
                return func
        kw = self.kwargs.copy()
        kw.update(kwargs)
        args = self.args + args
        return self.__class__(self.name, args=args, kwargs=kw)
conftest.py 文件源码 项目:schul_cloud_resources_server_tests 作者: schul-cloud 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def step(function):
    """Allow pytest -m stepX to run test up to a certain number."""
    step_number = len(_steps) + 1
    step_only_marker = "step{}only".format(step_number)
    marker_only = getattr(pytest.mark, step_only_marker)
    step_marker = "step{}".format(step_number)
    marker = getattr(pytest.mark, step_marker)
    def mark_function(marker):
        marker(function)
    for mark_step in _steps:
        mark_step(marker)
    _steps.append(mark_function)
    return marker_only(marker(function))
plugin.py 文件源码 项目:pytest-pypom-navigation 作者: tierratelematics 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def pytest_configure(config):
    # register an additional marker
    config.addinivalue_line(
        "markers",
        "skip_skins(skins): mark test to be skipped for the given skin ids"
    )
plugin.py 文件源码 项目:pytest-pypom-navigation 作者: tierratelematics 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def skip_skins(skins):
    """
    Decorator to mark tests to be skipped for the given skin ids.

    ie. @skip_skins(['skin1', 'skin2'])
    :return pytest.mark:
    """
    return pytest.mark.skip_skins(skins)
test_pluginmanager.py 文件源码 项目:GSM-scanner 作者: yosriayed 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_namespace_has_default_and_env_plugins(testdir):
    p = testdir.makepyfile("""
        import pytest
        pytest.mark
    """)
    result = testdir.runpython(p)
    assert result.ret == 0
mark.py 文件源码 项目:GSM-scanner 作者: yosriayed 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def pytest_namespace():
    return {'mark': MarkGenerator()}
mark.py 文件源码 项目:GSM-scanner 作者: yosriayed 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def pytest_addoption(parser):
    group = parser.getgroup("general")
    group._addoption(
        '-k',
        action="store", dest="keyword", default='', metavar="EXPRESSION",
        help="only run tests which match the given substring expression. "
             "An expression is a python evaluatable expression "
             "where all names are substring-matched against test names "
             "and their parent classes. Example: -k 'test_method or test "
             "other' matches all test functions and classes whose name "
             "contains 'test_method' or 'test_other'. "
             "Additionally keywords are matched to classes and functions "
             "containing extra names in their 'extra_keyword_matches' set, "
             "as well as functions which have names assigned directly to them."
    )

    group._addoption(
        "-m",
        action="store", dest="markexpr", default="", metavar="MARKEXPR",
        help="only run tests matching given mark expression.  "
             "example: -m 'mark1 and not mark2'."
    )

    group.addoption(
        "--markers", action="store_true",
        help="show markers (builtin, plugin and per-project ones)."
    )

    parser.addini("markers", "markers for test functions", 'linelist')
mark.py 文件源码 项目:GSM-scanner 作者: yosriayed 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def pytest_cmdline_main(config):
    import _pytest.config
    if config.option.markers:
        config._do_configure()
        tw = _pytest.config.create_terminal_writer(config)
        for line in config.getini("markers"):
            name, rest = line.split(":", 1)
            tw.write("@pytest.mark.%s:" % name, bold=True)
            tw.line(rest)
            tw.line()
        config._ensure_unconfigure()
        return 0
mark.py 文件源码 项目:GSM-scanner 作者: yosriayed 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def pytest_configure(config):
    import pytest
    if config.option.strict:
        pytest.mark._config = config
helper.py 文件源码 项目:allure-python 作者: allure-framework 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def decorate_as_label(self, label_type, labels):
        allure_label_marker = '{prefix}.{label_type}'.format(prefix=ALLURE_LABEL_PREFIX, label_type=label_type)
        allure_label = getattr(pytest.mark, allure_label_marker)
        return allure_label(*labels, label_type=label_type)
helper.py 文件源码 项目:allure-python 作者: allure-framework 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def decorate_as_link(self, url, link_type, name):
        allure_link_marker = '{prefix}.{link_type}'.format(prefix=ALLURE_LINK_PREFIX, link_type=link_type)
        pattern = dict(self.config.option.allure_link_pattern).get(link_type, u'{}')
        url = pattern.format(url)
        allure_link = getattr(pytest.mark, allure_link_marker)
        return allure_link(url, name=name, link_type=link_type)


问题


面经


文章

微信
公众号

扫码关注公众号