Пример #1
0
def test_invalid_argvalues_message():
    """ Check that the error message is friendly when the fixture_ref is misused"""
    with pytest.raises(InvalidParamsList) as exc_info:
        parametrize("fixture_a", fixture_ref('a'))
    assert str(exc_info.value).startswith(
        "Invalid parameters list (`argvalues`) in pytest parametrize. "
        "`list(argvalues)` returned an error.")
Пример #2
0
    def test_getcallspecs(new_style):
        if new_style:
            parametrizer = parametrize(
                a=[1, pytest.param('12', marks=pytest.mark.skip)],
                idgen="a={a}")
        else:
            parametrizer = parametrize(
                'a',
                [1, pytest.param('12', marks=pytest.mark.skip, id='hey')],
                ids=['oh', 'my'])

        @parametrizer
        def test_foo(a):
            pass

        calls = get_callspecs(test_foo)

        assert len(calls) == 2
        assert calls[0].funcargs == dict(a=1)
        assert calls[0].id == 'a=1' if new_style else 'oh'
        assert calls[0].marks == []

        assert calls[1].funcargs == dict(a='12')
        assert calls[1].id == 'a=12' if new_style else 'hey'
        assert calls[1].marks[0].name == 'skip'
Пример #3
0
def test_fixture_refs_are_not_supported_when_decorating_classes():
    class TestCls:
        pass

    with pytest.raises(NotImplementedError) as e:
        parametrize(foo=("bar", a))(TestCls)

    assert str(e.value).startswith(
        "@parametrize can not be used to decorate a Test class")
Пример #4
0

@fixture()
def cluster(unittest_config) -> Iterable[Cluster]:
    try:
        cluster = Cluster()
    except NoBrokersAvailable as ex:
        print(unittest_config.bootstrap_servers)
        raise ex

    yield cluster


@fixture()
def state(unittest_config) -> State:
    return State()


def check_and_load_yaml(output: str) -> Dict:
    assert output[0] != "{", "non json output starts with '{'"
    assert output[-2] != "}" and output[
        -1] != "}", "non json output ends with '}'"
    return yaml.safe_load(output)


FORMATS_AND_LOADERS = [("yaml", check_and_load_yaml), ("json", json.loads)]

parameterized_output_formats = parametrize("output_format, loader",
                                           FORMATS_AND_LOADERS,
                                           ids=["yaml_output", "json_output"])