def equal_test_conditions(testapi_input, nfvbench_input):
    """Check test conditions in behave scenario results record.

    Check whether a behave scenario results record from testapi matches a given
    nfvbench input, ie whether the record comes from a test done under the same
    conditions (frame size, flow count, ...)

    Args:
        testapi_input: dict holding the test conditions of a behave scenario
            results record from testapi

        nfvbench_input: dict of nfvbench test parameters (reference)

    The following dict keys are currently supported:
        - mandatory keys: 'duration_sec', 'frame_sizes', 'flow_count', 'rate'
        - optional keys: 'user_label', 'flavor_type'

    Optional keys are taken into account only when they can be found in
    `nfvbench_input`, else they are ignored.

    Returns:
        True if test conditions match, else False.

    """
    # Select required keys (other keys can be not set or unconsistent between scenarios)
    required_keys = ['duration_sec', 'frame_sizes', 'flow_count', 'rate']
    if 'user_label' in nfvbench_input:
        required_keys.append('user_label')
    if 'flavor_type' in nfvbench_input:
        required_keys.append('flavor_type')

    try:
        testapi_subset = {k: testapi_input[k] for k in required_keys}
        nfvbench_subset = {k: nfvbench_input[k] for k in required_keys}
        return testapi_subset == nfvbench_subset
    except KeyError:
        # Fail the comparison if a required key is missing from one of the dicts
        return False