How to use the pytest.param function in pytest

To help you get started, we’ve selected a few pytest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jdkandersson / OpenAlchemy / tests / open_alchemy / helpers / test_get_ext_prop.py View on Github external
        pytest.param("x-generated", True, id="x-generated",),
        pytest.param("x-inherits", True, id="x-inherits bool",),
        pytest.param("x-inherits", "Parent", id="x-inherits string",),
    ],
)
@pytest.mark.helper
def test_valid(name, value):
    """
    GIVEN property and valid value
    WHEN get is called with a source made of the property and value
    THEN the value is returned.
    """
    source = {name: value}

    returned_value = helpers.ext_prop.get(source=source, name=name)

    assert returned_value == value
github explosion / spacy-models / tests / lang / en / test_parser.py View on Github external
pytest.param("1.) The first item. 2.) The second item.", ["1.) The first item.", "2.) The second item."], marks=pytest.mark.xfail()),
    pytest.param("1) The first item 2) The second item", ["1) The first item", "2) The second item"], marks=pytest.mark.xfail()),
    ("1) The first item. 2) The second item.", ["1) The first item.", "2) The second item."]),
    pytest.param("1. The first item 2. The second item", ["1. The first item", "2. The second item"], marks=pytest.mark.xfail()),
    pytest.param("1. The first item. 2. The second item.", ["1. The first item.", "2. The second item."], marks=pytest.mark.xfail()),
    pytest.param("• 9. The first item • 10. The second item", ["• 9. The first item", "• 10. The second item"], marks=pytest.mark.xfail()),
    pytest.param("⁃9. The first item ⁃10. The second item", ["⁃9. The first item", "⁃10. The second item"], marks=pytest.mark.xfail()),
    pytest.param("a. The first item b. The second item c. The third list item", ["a. The first item", "b. The second item", "c. The third list item"], marks=pytest.mark.xfail()),
    ("This is a sentence\ncut off in the middle because pdf.", ["This is a sentence\ncut off in the middle because pdf."]),
    ("It was a cold \nnight in the city.", ["It was a cold \nnight in the city."]),
    pytest.param("features\ncontact manager\nevents, activities\n", ["features", "contact manager", "events, activities"], marks=pytest.mark.xfail()),
    pytest.param("You can find it at N°. 1026.253.553. That is where the treasure is.", ["You can find it at N°. 1026.253.553.", "That is where the treasure is."], marks=pytest.mark.xfail()),
    ("She works at Yahoo! in the accounting department.", ["She works at Yahoo! in the accounting department."]),
    ("We make a good team, you and I. Did you see Albert I. Jones yesterday?", ["We make a good team, you and I.", "Did you see Albert I. Jones yesterday?"]),
    ("Thoreau argues that by simplifying one’s life, “the laws of the universe will appear less complex. . . .”", ["Thoreau argues that by simplifying one’s life, “the laws of the universe will appear less complex. . . .”"]),
    pytest.param(""""Bohr [...] used the analogy of parallel stairways [...]" (Smith 55).""", ['"Bohr [...] used the analogy of parallel stairways [...]" (Smith 55).'], marks=pytest.mark.xfail()),
    ("If words are left off at the end of a sentence, and that is all that is omitted, indicate the omission with ellipsis marks (preceded and followed by a space) and then indicate the end of the sentence with a period . . . . Next sentence.", ["If words are left off at the end of a sentence, and that is all that is omitted, indicate the omission with ellipsis marks (preceded and followed by a space) and then indicate the end of the sentence with a period . . . .", "Next sentence."]),
    ("I never meant that.... She left the store.", ["I never meant that....", "She left the store."]),
    pytest.param("I wasn’t really ... well, what I mean...see . . . what I'm saying, the thing is . . . I didn’t mean it.", ["I wasn’t really ... well, what I mean...see . . . what I'm saying, the thing is . . . I didn’t mean it."], marks=pytest.mark.xfail()),
    pytest.param("One further habit which was somewhat weakened . . . was that of combining words into self-interpreting compounds. . . . The practice was not abandoned. . . .", ["One further habit which was somewhat weakened . . . was that of combining words into self-interpreting compounds.", ". . . The practice was not abandoned. . . ."], marks=pytest.mark.xfail()),
    pytest.param("Hello world.Today is Tuesday.Mr. Smith went to the store and bought 1,000.That is a lot.", ["Hello world.", "Today is Tuesday.", "Mr. Smith went to the store and bought 1,000.", "That is a lot."], marks=pytest.mark.xfail())
]
# fmt: on


@pytest.mark.skip
@pytest.mark.parametrize("text,expected_sents", TEST_CASES_SBD)
def test_en_sbd_prag(NLP, text, expected_sents):
    """SBD tests from Pragmatic Segmenter"""
    doc = NLP(text)
    sents = []
    for sent in doc.sents:
github ikalnytskyi / holocron / tests / _processors / test_prettyuri.py View on Github external
        pytest.param(5),
        pytest.param(10),
    ],
)
def test_item_many(testapp, amount):
    """Prettyuri processor has to work with stream."""

    stream = prettyuri.process(
        testapp,
        [
            holocron.Item(
                {"destination": pathlib.Path("about", "%d.html" % i)}
            )
            for i in range(amount)
        ],
    )
github williballenthin / python-idb / tests / fixtures.py View on Github external
sversion = {500: "v5.0", 695: "v6.95", 700: "v7.0b",}[version]

        sbitness, filename = {
            32: ("x32", "kernel32.idb"),
            64: ("x64", "kernel32.i64"),
        }[bitness]

        if (version, bitness) in COMMON_FIXTURES:
            db = COMMON_FIXTURES[(version, bitness)]
        else:
            path = os.path.join(CD, "data", sversion, sbitness, filename)
            db = load_idb(path)

        if marks:
            params.append(pytest.param(db, version, bitness, expected, marks=marks))
        else:
            params.append(pytest.param(db, version, bitness, expected))

        ids.append(sversion + "/" + sbitness)

    return pytest.mark.parametrize(
        "kernel32_idb,version,bitness,expected", params, ids=ids
    )
github informatics-lab / forest / test / test_util.py View on Github external
    pytest.param(
        cftime.DatetimeGregorian(2020, 1, 1),
        cftime.DatetimeGregorian(2021, 1, 1),
        id="cftime.DatetimeGregorian"),
])
def test_replace(given, expect):
    result = util.replace(given, year=2021)
    assert result == expect
github allenai / scispacy / tests / custom_tests / test_custom_tokenizer.py View on Github external
import pytest

TEST_CASES = [("using a bag-of-words model", ["using", "a", "bag-of-words", "model"]),
              ("activators of cAMP- and cGMP-dependent protein", ["activators", "of", "cAMP-", "and", "cGMP-dependent", "protein"]),
              ("phorbol 12-myristate 13-acetate, caused almost", ["phorbol", "12-myristate", "13-acetate", ",", "caused", "almost"]),
              pytest.param("let C(j) denote", ["let", "C(j)", "denote"], marks=pytest.mark.xfail),
              pytest.param("let (C(j)) denote", ["let", "(", "C(j)", ")", "denote"], marks=pytest.mark.xfail),
              pytest.param("let C{j} denote", ["let", "C{j}", "denote"], marks=pytest.mark.xfail),
              pytest.param("for the camera(s) and manipulator(s)", ["for", "the", "camera(s)", "and", "manipulator(s)"], marks=pytest.mark.xfail),
              ("the (TRAP)-positive genes", ["the", "(TRAP)-positive", "genes"]),
              ("the {TRAP}-positive genes", ["the", "{TRAP}-positive", "genes"]),
              ("for [Ca2+]i protein", ["for", "[Ca2+]i", "protein"]),
              pytest.param("for pyrilamine[3H] protein", ["for", "pyrilamine[3H]", "protein"], marks=pytest.mark.xfail),
              ("this is (normal) parens", ["this", "is", "(", "normal", ")", "parens"]),
              ("this is [normal] brackets", ["this", "is", "[", "normal", "]", "brackets"]),
              ("this is {normal} braces", ["this", "is", "{", "normal", "}", "braces"]),
              ("in the lan-\nguage of the", ["in", "the", "language", "of", "the"]),
              ("in the lan-\n\nguage of the", ["in", "the", "language", "of", "the"]),
              ("in the lan- \nguage of the", ["in", "the", "language", "of", "the"]),
              ("in the lan- \n\nguage of the", ["in", "the", "language", "of", "the"]),
              ("a 28× 28 image", ["a", "28", "×", "28", "image"]),
              ("a 28×28 image", ["a", "28", "×", "28", "image"]),
              ("a 28 × 28 image", ["a", "28", "×", "28", "image"]),
              ("the neurons’ activation", ["the", "neurons", "’", "activation"]),
github jdkandersson / OpenAlchemy / tests / open_alchemy / helpers / test_get_ext_prop.py View on Github external
        pytest.param("x-tablename", "table 1", id="x-tablename",),
        pytest.param("x-de-$ref", "Table1", id="x-de-$ref",),
        pytest.param("x-dict-ignore", True, id="x-dict-ignore",),
        pytest.param("x-generated", True, id="x-generated",),
        pytest.param("x-inherits", True, id="x-inherits bool",),
        pytest.param("x-inherits", "Parent", id="x-inherits string",),
    ],
)
@pytest.mark.helper
def test_valid(name, value):
    """
    GIVEN property and valid value
    WHEN get is called with a source made of the property and value
    THEN the value is returned.
    """
    source = {name: value}
github ansible / ansible-lint / test / TestUtils.py View on Github external
    pytest.param({'git': {'version': 'abc'}, 'args': {'repo': 'blah', 'dest': 'xyz'}},
                 ({'git': {'version': 'abc', 'repo': 'blah', 'dest': 'xyz'}},
                  {"git": 'version=abc repo=blah dest=xyz'},
                  {"git": None, "args": {'repo': 'blah', 'dest': 'xyz', 'version': 'abc'}},
                  ),
                 id='args')
))
def test_normalize(reference_form, alternate_forms):
    normal_form = utils.normalize_task(reference_form, 'tasks.yml')

    for form in alternate_forms:
        assert normal_form == utils.normalize_task(form, 'tasks.yml')
github mdtraj / mdtraj / examples / test_examples.py View on Github external
Adapted from https://gist.github.com/minrk/2620876.
"""
from __future__ import print_function
import os
import sys

import nbformat
import pytest
from jupyter_client import KernelManager
from six.moves.queue import Empty

FLAKEY_LIST = ['centroids.ipynb', 'native-contact.ipynb', 'hbonds.ipynb']
TIMEOUT = 60  # seconds

test_dir = os.path.dirname(os.path.abspath(__file__))
examples = [pytest.param(fn, marks=pytest.mark.flaky) if fn in FLAKEY_LIST else fn
            for fn in os.listdir(test_dir) if fn.endswith('.ipynb')]


@pytest.fixture(params=examples)
def example_fn(request):
    if 'openmm' in request.param:
        try:
            from simtk.openmm import app
        except ImportError:
            pytest.skip("Openmm required for example notebook `{}`".format(request.param))

    cwd = os.path.abspath('.')
    os.chdir(test_dir)
    yield request.param
    os.chdir(cwd)
github gwpy / gwpy / gwpy / testing / fixtures.py View on Github external
    pytest.param(True, id='usetex', marks=SKIP_TEX)
])
def usetex(request):
    """Repeat a test with matplotlib's `text.usetex` param False and True.

    If TeX is not available on the test machine (determined by
    `gwpy.plot.tex.has_tex()`), the usetex=True tests will be skipped.
    """
    use_ = request.param
    with rc_context(rc={'text.usetex': use_}):
        yield use_