当前位置: 首页>>代码示例>>Python>>正文


Python pytest.param函数代码示例

本文整理汇总了Python中pytest.param函数的典型用法代码示例。如果您正苦于以下问题:Python param函数的具体用法?Python param怎么用?Python param使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了param函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: iter_struct_object_dtypes

def iter_struct_object_dtypes():
    """
    Iterates over a few complex dtypes and object pattern which
    fill the array with a given object (defaults to a singleton).

    Yields
    ------
    dtype : dtype
    pattern : tuple
        Structured tuple for use with `np.array`.
    count : int
        Number of objects stored in the dtype.
    singleton : object
        A singleton object. The returned pattern is constructed so that
        all objects inside the datatype are set to the singleton.
    """
    obj = object()

    dt = np.dtype([('b', 'O', (2, 3))])
    p = ([[obj] * 3] * 2,)
    yield pytest.param(dt, p, 6, obj, id="<subarray>")

    dt = np.dtype([('a', 'i4'), ('b', 'O', (2, 3))])
    p = (0, [[obj] * 3] * 2)
    yield pytest.param(dt, p, 6, obj, id="<subarray in field>")

    dt = np.dtype([('a', 'i4'),
                   ('b', [('ba', 'O'), ('bb', 'i1')], (2, 3))])
    p = (0, [[(obj, 0)] * 3] * 2)
    yield pytest.param(dt, p, 6, obj, id="<structured subarray 1>")

    dt = np.dtype([('a', 'i4'),
                   ('b', [('ba', 'O'), ('bb', 'O')], (2, 3))])
    p = (0, [[(obj, obj)] * 3] * 2)
    yield pytest.param(dt, p, 12, obj, id="<structured subarray 2>")
开发者ID:anntzer,项目名称:numpy,代码行数:35,代码来源:test_dtype.py

示例2: pytest_generate_tests

def pytest_generate_tests(metafunc):
    if 'example' in metafunc.fixturenames:
        config = metafunc.config
        examples = get_all_examples(config)

        def marks(example):
            result = []
            if example.is_skip:
                result.append(pytest.mark.skip(reason="skipping %s" % example.relpath))
            if example.is_xfail and not example.no_js:
                result.append(pytest.mark.xfail(reason="xfail %s" % example.relpath, strict=True))
            return result

        if 'js_example' in metafunc.fixturenames:
            params = [ pytest.param(e.path, e, config, marks=marks(e)) for e in examples if e.is_js ]
            metafunc.parametrize('js_example,example,config', params)
        if 'file_example' in metafunc.fixturenames:
            params = [ pytest.param(e.path, e, config, marks=marks(e)) for e in examples if e.is_file ]
            metafunc.parametrize('file_example,example,config', params)
        if 'server_example' in metafunc.fixturenames:
            params = [ pytest.param(e.path, e, config, marks=marks(e)) for e in examples if e.is_server ]
            metafunc.parametrize('server_example,example,config', params)
        if 'notebook_example' in metafunc.fixturenames:
            params = [ pytest.param(e.path, e, config, marks=marks(e)) for e in examples if e.is_notebook ]
            metafunc.parametrize('notebook_example,example,config', params)
开发者ID:digitalsatori,项目名称:Bokeh,代码行数:25,代码来源:examples_report.py

示例3: test_pytest_param_id_requires_string

def test_pytest_param_id_requires_string():
    with pytest.raises(TypeError) as excinfo:
        pytest.param(id=True)
    msg, = excinfo.value.args
    if six.PY2:
        assert msg == "Expected id to be a string, got <type 'bool'>: True"
    else:
        assert msg == "Expected id to be a string, got <class 'bool'>: True"
开发者ID:nicoddemus,项目名称:pytest,代码行数:8,代码来源:test_mark.py

示例4: __call__

 def __call__(self, f):
     params = []
     for product in _products:
         if product not in _active_products:
             params.append(pytest.param(product, marks=pytest.mark.skip(reason="wrong toxenv")))
         elif product in self.marks:
             params.append(pytest.param(product, marks=self.marks[product]))
         else:
             params.append(product)
     return pytest.mark.parametrize(self.arg, params)(f)
开发者ID:Honry,项目名称:web-platform-tests,代码行数:10,代码来源:base.py

示例5: pandas_skip

def pandas_skip(test):  # pragma: no cover
    """Skips a test if the pandas plugin is not available."""
    # Check libraries are present
    if not has_pandas():
        return pytest.param(test, marks=pytest.mark.skip(reason='the pandas plugin requires pandas'))
    # Check library versions
    minor = LooseVersion(pd.__version__).version[1]
    if minor not in (16, 17, 18, 20, 21, 22, 23):
        reason = 'these tests do not support pandas version %s' % pd.__version__
        return pytest.param(test, marks=pytest.mark.skip(reason=reason))
    return test
开发者ID:sdvillal,项目名称:whatami,代码行数:11,代码来源:fixtures.py

示例6: write_read_engines

def write_read_engines(xfail_arrow_to_fastparquet=True):
    if xfail_arrow_to_fastparquet:
        xfail = (pytest.mark.xfail(reason="Can't read arrow directories with fastparquet"),)
    else:
        xfail = ()
    ff = () if fastparquet else (pytest.mark.skip(reason='fastparquet not found'),)
    aa = () if pq else (pytest.mark.skip(reason='pyarrow not found'),)
    engines = [pytest.param('fastparquet', 'fastparquet', marks=ff),
               pytest.param('pyarrow', 'pyarrow', marks=aa),
               pytest.param('fastparquet', 'pyarrow', marks=ff + aa),
               pytest.param('pyarrow', 'fastparquet', marks=ff + aa + xfail)]
    return pytest.mark.parametrize(('write_engine', 'read_engine'), engines)
开发者ID:postelrich,项目名称:dask,代码行数:12,代码来源:test_parquet.py

示例7: write_read_engines

def write_read_engines(**kwargs):
    """Product of both engines for write/read:

    To add custom marks, pass keyword of the form: `mark_writer_reader=reason`,
    or `mark_engine=reason` to apply to all parameters with that engine."""
    backends = {'pyarrow', 'fastparquet'}
    marks = {(w, r): [] for w in backends for r in backends}

    # Skip if uninstalled
    for name, exists in [('fastparquet', fastparquet), ('pyarrow', pq)]:
        val = pytest.mark.skip(reason='%s not found' % name)
        if not exists:
            for k in marks:
                if name in k:
                    marks[k].append(val)

    # Custom marks
    for kw, val in kwargs.items():
        kind, rest = kw.split('_', 1)
        key = tuple(rest.split('_'))
        if (kind not in ('xfail', 'skip') or len(key) > 2 or
                set(key).difference(backends)):
            raise ValueError("unknown keyword %r" % kw)
        val = getattr(pytest.mark, kind)(reason=val)
        if len(key) == 2:
            marks[key].append(val)
        else:
            for k in marks:
                if key in k:
                    marks[k].append(val)

    return pytest.mark.parametrize(('write_engine', 'read_engine'),
                                   [pytest.param(*k, marks=tuple(v))
                                    for (k, v) in sorted(marks.items())])
开发者ID:caseyclements,项目名称:dask,代码行数:34,代码来源:test_parquet.py

示例8: _get_pip_versions

def _get_pip_versions():
    # This fixture will attempt to detect if tests are being run without
    # network connectivity and if so skip some tests

    network = True
    if not os.environ.get('NETWORK_REQUIRED', False):  # pragma: nocover
        try:
            from urllib.request import urlopen
            from urllib.error import URLError
        except ImportError:
            from urllib2 import urlopen, URLError # Python 2.7 compat

        try:
            urlopen('https://pypi.org', timeout=1)
        except URLError:
            # No network, disable most of these tests
            network = False

    network_versions = [
        'pip==9.0.3',
        'pip==10.0.1',
        'pip==18.1',
        'pip==19.0.1',
        'https://github.com/pypa/pip/archive/master.zip',
    ]

    versions = [None] + [
        pytest.param(v, **({} if network else {'marks': pytest.mark.skip}))
        for v in network_versions
    ]

    return versions
开发者ID:pypa,项目名称:setuptools,代码行数:32,代码来源:test_virtualenv.py

示例9: pytest_generate_tests

def pytest_generate_tests(metafunc):
    """ zipper auth_modes and auth_prov together and drop the nonsensical combos """
    # TODO use supportability and provider type+version parametrization
    argnames = ['auth_mode', 'prov_key', 'user_type', 'auth_user']
    argvalues = []
    idlist = []
    if 'auth_providers' not in auth_data:
        metafunc.parametrize(argnames, [
            pytest.param(
                None, None, None, None,
                marks=pytest.mark.uncollect("auth providers data missing"))])
        return
    # Holy nested loops, batman
    # go through each mode, then each auth type, and find auth providers matching that type
    # go through each user type for the given mode+auth_type (from param_maps above)
    # for each user type, find users in the yaml matching user_type an on the given auth provider
    # add parametrization for matching set of mode, auth_provider key, user_type, and user_dict
    # set id, use the username from userdict instead of an auto-generated "auth_user[\d]" ID
    for mode in test_param_maps.keys():
        for auth_type in test_param_maps.get(mode, {}):
            eligible_providers = {key: prov_dict
                                  for key, prov_dict in iteritems(auth_data.auth_providers)
                                  if prov_dict.type == auth_type}
            for user_type in test_param_maps[mode][auth_type]['user_types']:
                for key, prov_dict in eligible_providers.items():
                    for user_dict in [u for u in auth_user_data(key, user_type) or []]:
                        if user_type in prov_dict.get('user_types', []):
                            argvalues.append((mode, key, user_type, user_dict))
                            idlist.append('-'.join([mode, key, user_type, user_dict.username]))
    metafunc.parametrize(argnames, argvalues, ids=idlist)
开发者ID:lcouzens,项目名称:cfme_tests,代码行数:30,代码来源:test_cfme_auth.py

示例10: filter_fixtures

def filter_fixtures(all_fixtures, fixtures_base_dir, mark_fn=None, ignore_fn=None):
    """
    Helper function for filtering test fixtures.

    - `fixtures_base_dir` should be the base directory that the fixtures were collected from.
    - `mark_fn` should be a function which either returns `None` or a `pytest.mark` object.
    - `ignore_fn` should be a function which returns `True` for any fixture
       which should be ignored.
    """
    for fixture_data in all_fixtures:
        fixture_path = fixture_data[0]
        fixture_relpath = os.path.relpath(fixture_path, fixtures_base_dir)

        if ignore_fn:
            if ignore_fn(fixture_relpath, *fixture_data[1:]):
                continue

        if mark_fn is not None:
            mark = mark_fn(fixture_relpath, *fixture_data[1:])
            if mark:
                yield pytest.param(
                    (fixture_path, *fixture_data[1:]),
                    marks=mark,
                )
                continue

        yield fixture_data
开发者ID:firefox0x,项目名称:py-evm,代码行数:27,代码来源:fixture_tests.py

示例11: parametrize_test_working_set_resolve

def parametrize_test_working_set_resolve(*test_list):
    idlist = []
    argvalues = []
    for test in test_list:
        (
            name,
            installed_dists,
            installable_dists,
            requirements,
            expected1, expected2
        ) = [
            strip_comments(s.lstrip()) for s in
            textwrap.dedent(test).lstrip().split('\n\n', 5)
        ]
        installed_dists = list(parse_distributions(installed_dists))
        installable_dists = list(parse_distributions(installable_dists))
        requirements = list(pkg_resources.parse_requirements(requirements))
        for id_, replace_conflicting, expected in (
            (name, False, expected1),
            (name + '_replace_conflicting', True, expected2),
        ):
            idlist.append(id_)
            expected = strip_comments(expected.strip())
            if re.match('\w+$', expected):
                expected = getattr(pkg_resources, expected)
                assert issubclass(expected, Exception)
            else:
                expected = list(parse_distributions(expected))
            argvalues.append(pytest.param(installed_dists, installable_dists,
                                          requirements, replace_conflicting,
                                          expected))
    return pytest.mark.parametrize('installed_dists,installable_dists,'
                                   'requirements,replace_conflicting,'
                                   'resolved_dists_or_exception',
                                   argvalues, ids=idlist)
开发者ID:pymedusa,项目名称:SickRage,代码行数:35,代码来源:test_working_set.py

示例12: parametrize

 def parametrize(*test_list, **format_dict):
     idlist = []
     argvalues = []
     for test in test_list:
         test_params = test.lstrip().split('\n\n', 3)
         name_kwargs = test_params.pop(0).split('\n')
         if len(name_kwargs) > 1:
             val = name_kwargs[1].strip()
             install_cmd_kwargs = ast.literal_eval(val)
         else:
             install_cmd_kwargs = {}
         name = name_kwargs[0].strip()
         setup_py_requires, setup_cfg_requires, expected_requires = (
             DALS(a).format(**format_dict) for a in test_params
         )
         for id_, requires, use_cfg in (
             (name, setup_py_requires, False),
             (name + '_in_setup_cfg', setup_cfg_requires, True),
         ):
             idlist.append(id_)
             marks = ()
             if requires.startswith('@xfail\n'):
                 requires = requires[7:]
                 marks = pytest.mark.xfail
             argvalues.append(pytest.param(requires, use_cfg,
                                           expected_requires,
                                           install_cmd_kwargs,
                                           marks=marks))
     return pytest.mark.parametrize(
         'requires,use_setup_cfg,'
         'expected_requires,install_cmd_kwargs',
         argvalues, ids=idlist,
     )
开发者ID:santazhang,项目名称:sandbox,代码行数:33,代码来源:test_egg_info.py

示例13: skipif_32bit

def skipif_32bit(param):
    """
    Skip parameters in a parametrize on 32bit systems. Specifically used
    here to skip leaf_size parameters related to GH 23440.
    """
    marks = pytest.mark.skipif(compat.is_platform_32bit(),
                               reason='GH 23440: int type mismatch on 32bit')
    return pytest.param(param, marks=marks)
开发者ID:bwignall,项目名称:pandas,代码行数:8,代码来源:test_interval_tree.py

示例14: cases_test_cont_basic

def cases_test_cont_basic():
    for distname, arg in distcont[:] + [(histogram_test_instance, tuple())]:
        if distname == 'levy_stable':
            continue
        elif distname in distslow:
            yield pytest.param(distname, arg, marks=pytest.mark.slow)
        else:
            yield distname, arg
开发者ID:anntzer,项目名称:scipy,代码行数:8,代码来源:test_continuous_basic.py

示例15: create_gradient_acquisition_fixtures

def create_gradient_acquisition_fixtures():
    # Create list of tuples of parameters with (fixture, tolerance) for acquisitions that gave gradients only
    parameters = []
    for acquisition in acquisition_tests:
        if acquisition.has_gradients:
            acquisition_name = acquisition.name
            lazy_fixture = pytest_lazyfixture.lazy_fixture(acquisition.name)
            parameters.append(pytest.param(lazy_fixture, acquisition.rmse_gradient_tolerance, id=acquisition_name))
    return parameters
开发者ID:JRetza,项目名称:emukit,代码行数:9,代码来源:test_acquisitions.py


注:本文中的pytest.param函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。