Beispiel #1
0
# {'passed': 9, 'skipped': 0, 'failed': 0}
# END META
from collections import OrderedDict
from itertools import product

import pytest

from pytest_harvest import create_results_bag_fixture, saved_fixture, get_session_synthesis_dct


@pytest.fixture(scope='module', autouse=True)
def store():
    return OrderedDict()


my_results = create_results_bag_fixture('store', name='my_results')

# parametrized fixture
fixture_params = ['A', 'B', 'C']


@pytest.fixture(params=fixture_params)
@saved_fixture('store')
def my_fix(request):
    """Our saved fixture, that will be saved in the store fixture"""
    # convert the parameter to a string so that the fixture is different from the parameter
    return "my_fix #%s" % request.param


# parametrized test
test_params = [10, 20]
Beispiel #2
0
    This test applies the algorithm with various parameters (`algo_param`)
    on various datasets (`dataset`). Accuracies are stored in a results
    bag (`results_bag`)
    """
    # apply the algorithm with param `algo_param` on dataset `dataset`
    accuracy = my_algorithm(algo_param, dataset)

    # store it in the results bag
    results_bag.accuracy = accuracy


# the result bag
# note: depending on your pytest version, the name used by pytest might be
# the variable name (left) or the one you provide in the 'name' argument so
# make sure they are identical!
results_bag = create_results_bag_fixture('store', name="results_bag")


@yield_fixture(scope='module', autouse=True)
def store(request):
    # setup: init the store
    store = OrderedDict()
    yield store
    # teardown: here you can collect all
    assert len(store['results_bag']) == 6
    print(dict(store['results_bag']))

    # retrieve the synthesis, merged with the fixture store
    results_dct = get_session_synthesis_dct(request.session,
                                            status_details=False,
                                            durations_in_ms=True,
Beispiel #3
0
# ---------- The function to test -------
def my_algorithm(param, data):
    # let's return a random accuracy !
    return random()


# ---------- Tests
# A module-scoped store
@pytest.fixture(scope='module', autouse=True)
def my_store():
    return OrderedDict()


# A module-scoped results bag fixture
my_results_bag = create_results_bag_fixture('my_store', name='my_results_bag')


@pytest.fixture(params=['A', 'B', 'C'])
@saved_fixture('my_store')
def dataset(request):
    """Represents a dataset fixture."""
    return "my dataset #%s" % request.param


@pytest.mark.parametrize("algo_param", [1, 2], ids=str)
def test_my_app_bench(algo_param, dataset, my_results_bag):
    """
    This test applies the algorithm with various parameters (`algo_param`)
    on various datasets (`dataset`).