예제 #1
0
def pytest_generate_tests(metafunc: Metafunc):
    """
    This runs at the end of the collection phase. We use this hook to generate
    the workflow_dir fixtures for custom test functions.
    :param metafunc: A function before it is fully parametrized.
    :return: None
    """
    # If workflow_dir is not present we do not need to parametrize it.
    if "workflow_dir" not in metafunc.fixturenames:
        return

    definition: FunctionDefinition = metafunc.definition
    marker: Optional[Mark] = definition.get_closest_marker(name="workflow")
    if marker is None:
        raise ValueError("workflow_dir can only be requested in tests marked"
                         " with the workflow mark.")

    workflow_names = get_workflow_names_from_workflow_marker(marker)
    if not workflow_names:
        raise ValueError(f"A workflow name or names should be defined in "
                         f"the workflow marker of {definition.nodeid}")

    workflow_temp_dir = metafunc.config.workflow_temp_dir  # type: ignore
    workflow_dirs = [Path(workflow_temp_dir, replace_whitespace(name))
                     for name in workflow_names]
    metafunc.parametrize("workflow_dir", workflow_dirs,
                         ids=workflow_names)
예제 #2
0
def pytest_generate_tests(metafunc: Metafunc) -> None:
    """Inject `dtype`, `data_type` (filter pandera DataTypes), `alias`, `data`
    fixtures from `dtype_fixtures`.
    """
    fixtures = [
        fixture for fixture in ("data_type", "dtype", "pd_dtype", "data")
        if fixture in metafunc.fixturenames
    ]
    arg_names = ",".join(fixtures)

    if arg_names:
        arg_values = []
        for dtypes, data in dtype_fixtures:
            for dtype, pd_dtype in dtypes.items():
                if "data_type" in fixtures and not (
                        isinstance(dtype, pa.DataType) or
                    (inspect.isclass(dtype)
                     and issubclass(dtype, pa.DataType))):
                    # not a pa.DataType class or instance
                    continue

                params = [dtype]
                if "pd_dtype" in fixtures:
                    params.append(pd_dtype)
                if "data" in fixtures:
                    params.append(data)
                arg_values.append(pretty_param(*params))

        metafunc.parametrize(arg_names, arg_values)
예제 #3
0
def pytest_generate_tests(metafunc: Metafunc) -> None:
    """
    Iterate through tests with length parameter and make
    sure tests will be executed with 1024 increment.
    """
    if 'length' in metafunc.fixturenames:
        metafunc.parametrize("length", [x * 1024 for x in [1, 5, 10]])
예제 #4
0
def pytest_generate_tests(metafunc: Metafunc) -> None:
    """
    Generate clients, brokers, matrix
    :param metafunc:
    :return:
    """
    if 'sender' in metafunc.fixturenames:
        g_senders = list(metafunc.config.option.sender)
        metafunc.parametrize('sender', g_senders, indirect=True)

    if 'receiver' in metafunc.fixturenames:
        g_receivers = list(metafunc.config.option.receiver)
        metafunc.parametrize('receiver', g_receivers, indirect=True)

    if 'broker' in metafunc.fixturenames:
        g_brokers = list(metafunc.config.option.broker)
        metafunc.parametrize('broker', g_brokers, indirect=True)

    if 'router' in metafunc.fixturenames:
        g_routers = list(metafunc.config.option.router)
        metafunc.parametrize('router', g_routers, indirect=True)

    if 'tls' in metafunc.fixturenames:
        g_tls = list(metafunc.config.option.tls)
        metafunc.parametrize('tls', g_tls, indirect=True)
예제 #5
0
def pytest_generate_tests(metafunc: Metafunc) -> None:
    """Generate tests for each API and server from pytest options.

    Both options has defaults, if the user adds the same option it will be duplicated, so we remove it.
    """
    if "api" in metafunc.fixturenames:
        metafunc.parametrize("api", list(set(metafunc.config.getoption("--tgn-api"))), indirect=True)
    metafunc.parametrize("server", list(set(metafunc.config.getoption("--tgn-server"))), indirect=True)
예제 #6
0
def parametrize_capabilities(metafunc: Metafunc):
    caps_list = get_marker_capabilites_list_or_none(metafunc)
    if ("sosu_webdriver_parameter_capabilities" in metafunc.fixturenames
            and caps_list is not None):
        metafunc.parametrize(
            "sosu_webdriver_parameter_capabilities",
            [pytest.param(c, id=c.slug) for c in caps_list],
        )
예제 #7
0
파일: conftest.py 프로젝트: thatcr/graphty
def pytest_generate_tests(metafunc: Metafunc) -> None:
    """Map decorator fixture to list of decorators to test."""
    import snake.shifter.wrapper

    decorators = [snake.shifter.wrapper.shift]

    if "decorator" in metafunc.fixturenames:
        metafunc.parametrize(
            "decorator", decorators, ids=[d.__module__ for d in decorators]
        )
예제 #8
0
def pytest_generate_tests(metafunc: Metafunc) -> None:
    if metafunc.config.option.repeat is not None:
        count = int(metafunc.config.option.repeat)
        # We're going to duplicate these tests by parametrizing them,
        # which requires that each test has a fixture to accept the parameter.
        # We can add a new fixture like so:
        metafunc.fixturenames.append('tmp_ct')
        # Now we parametrize. This is what happens when we do e.g.,
        # @pytest.mark.parametrize('tmp_ct', range(count))
        # def test_foo(): pass
        metafunc.parametrize('tmp_ct', range(count))
예제 #9
0
def pytest_generate_tests(metafunc: Metafunc) -> None:
    global argnames
    idlist = []
    argvalues = []
    if metafunc.cls is not None:
        for scenario in metafunc.cls.scenarios:
            idlist.append(scenario[0])
            items = scenario[1].items()
            argnames = [x[0] for x in items]
            argvalues.append(([x[1] for x in items]))
        metafunc.parametrize(argnames, argvalues, ids=idlist, scope="class")
예제 #10
0
def pytest_generate_tests(metafunc: Metafunc) -> None:
    """
    Checks if the the nuts pytest parametrization scheme exists (@pytest.mark.nuts)
    to generate tests based on that information.
    """
    nuts = metafunc.definition.get_closest_marker("nuts")
    if nuts:
        parametrize_args, parametrize_data = get_parametrize_data(
            metafunc, *nuts.args, **nuts.kwargs
        )
        metafunc.parametrize(parametrize_args, parametrize_data)
예제 #11
0
def pytest_generate_tests(metafunc: Metafunc) -> None:
    """
    Iterate through tests with length parameter and make
    sure tests will be executed with 1024 increment.
    """

    clusters: list = list(metafunc.config.option.cluster)
    clusters_count: int = len(clusters)
    clients_cluster: list = [
        client + '_' + str(cluster) for client, cluster in itertools.product(
            clients, range(0, clusters_count))
    ]

    routers: list = [
        'router' + '_' + str(cluster) for cluster in range(0, clusters_count)
    ]
    senders: list = ['sender' + '_' + client for client in clients_cluster]
    receivers: list = ['receiver' + '_' + client for client in clients_cluster]

    if 'msg_length' in metafunc.fixturenames:
        # metafunc.parametrize("msg_length", [2 ** x for x in range(8, 15)])
        msg_lengths: list = list(metafunc.config.option.msg_length)
        metafunc.parametrize("msg_length", msg_lengths)

    if 'sender' in metafunc.fixturenames:
        metafunc.parametrize('sender', senders, indirect=True)

    if 'receiver' in metafunc.fixturenames:
        metafunc.parametrize('receiver', receivers, indirect=True)

    if 'router_cluster' in metafunc.fixturenames:
        metafunc.parametrize('router_cluster', routers, indirect=True)
예제 #12
0
def pytest_generate_tests(metafunc: Metafunc):
    start_daemon()
    for fixture in metafunc.fixturenames:
        if fixture == "dit_json":
            test_dicts = list(load_from_json())
            titles = []
            for test_dict in test_dicts:
                if len(test_dict["title"]) > 62:
                    raise ValueError(
                        f"The test titled [{test_dict['title']}] is too long.")
                titles.append(test_dict["title"])
            metafunc.parametrize(argnames=fixture,
                                 argvalues=test_dicts,
                                 ids=titles)
예제 #13
0
    def pytest_generate_tests(self, metafunc: Metafunc) -> None:
        """
        It is basically a parametrized pytest fixture, but due to the fact that
        fixtures still don't work in collection time, this solution is necessary
        to provide a fixture that uses attributes overwritten by subclasses as
        fixture 'params' argument.

        https://docs.pytest.org/en/latest/parametrize.html#pytest-generate-tests

        Args:
            metafunc: pytest fixture-like object.

        """
        if 'url' in metafunc.fixturenames:
            metafunc.parametrize('url', self.urls, scope='class')
예제 #14
0
def pytest_generate_tests(metafunc: Metafunc):
    sources = [
        Arutz7Source(),
        HaaretzSource(),
        IsraelHayomSource(),
        MaarivSource(),
        N12Source(),
        News13Source(),
        News0404Source(),
        WallaSource(),
        YnetSource(),
    ]
    metafunc.parametrize(
        ("source", "root_content"),
        zip(sources, [source.get_root_content() for source in sources]),
        ids=[source.name for source in sources])
예제 #15
0
def _generate_tables_with_views_tests(metafunc: Metafunc):
    table_arg_name = "test_table"
    view_arg_name = "test_view"
    if {table_arg_name, view_arg_name}.issubset(set(metafunc.fixturenames)):
        metafunc.parametrize(
            (table_arg_name, view_arg_name),
            [
                (mock.create_autospec(db.UserRole), mock.create_autospec(views.UserView)),
                (mock.create_autospec(db.GroupRole), mock.create_autospec(views.GroupView)),
                (mock.create_autospec(db.Feature), mock.create_autospec(views.FeatureView)),
                (mock.create_autospec(db.TestRun), mock.create_autospec(views.TestRunView)),
                (mock.create_autospec(db.Draft), mock.create_autospec(views.DraftView)),
                (mock.create_autospec(db.Emulation), mock.create_autospec(views.EmulationView)),
                (mock.create_autospec(db.EmulationRun), mock.create_autospec(views.EmulationRunView)),
                (mock.create_autospec(db.TestUser), mock.create_autospec(views.TestUserView)),
            ],
        )
예제 #16
0
def pytest_generate_tests(metafunc: Metafunc):
    parametrized_type_fixture = "parametrized_type"
    type_parameters_fixture = "type_parameters"
    parametrized_types = [
        (list, [str]),
        (set, [str]),
        (frozenset, [str]),
        (tuple, [str]),
        (dict, [str, str]),
    ]

    if parametrized_type_fixture in metafunc.fixturenames:
        metafunc.parametrize(
            parametrized_type_fixture,
            [o[0] for o in parametrized_types],
            ids=[str(s[0]) for s in parametrized_types],
        )
        metafunc.parametrize(
            type_parameters_fixture,
            [o[1] for o in parametrized_types],
        )
예제 #17
0
파일: conftest.py 프로젝트: rvais/iqa-one
def pytest_generate_tests(metafunc: Metafunc) -> None:
    if 'sender' in metafunc.fixturenames:
        senders = list(metafunc.config.option.sender)
        metafunc.parametrize('sender', senders, indirect=True)

    if 'receiver' in metafunc.fixturenames:
        receivers = list(metafunc.config.option.receiver)
        metafunc.parametrize('receiver', receivers, indirect=True)

    if 'broker' in metafunc.fixturenames:
        brokers = list(metafunc.config.option.broker)
        metafunc.parametrize('broker', brokers, indirect=True)

    if 'router' in metafunc.fixturenames:
        routers = list(metafunc.config.option.router)
        metafunc.parametrize('router', routers, indirect=True)
예제 #18
0
def pytest_generate_tests(metafunc: Metafunc) -> None:
    test_feature_container_name = "test_feature_container"
    if test_feature_container_name in metafunc.fixturenames:
        metafunc.parametrize(test_feature_container_name,
                             get_test_feature_containers())
예제 #19
0
def pytest_generate_tests(metafunc: Metafunc):
    if 'param1' in metafunc.fixturenames:
        metafunc.parametrize('param1',
                             metafunc.module.addvalues,
                             ids=metafunc.module.addkeys,
                             scope='function')
예제 #20
0
def pytest_generate_tests(metafunc: Metafunc) -> None:
    metafunc.parametrize("repo", ALL_TESTS)
예제 #21
0
def pytest_generate_tests(metafunc: Metafunc) -> None:
    if metafunc.config.option.repeat is None:
        return
    count = int(metafunc.config.option.repeat)
    metafunc.fixturenames.append('_')
    metafunc.parametrize('_', range(count))
예제 #22
0
def pytest_generate_tests(metafunc: Metafunc) -> None:
    """
    Iterations for EdgeRouterMode02 test_suite
    """
    clients: List[str] = [
        "java",
        "python",
        "nodejs",
    ]

    senders_comb: List[str] = ['sender' + '_' + client for client in clients]
    receivers_comb: List[str] = [
        'receiver' + '_' + client for client in clients
    ]

    # Routers
    iqa: Instance = metafunc.config.iqa
    routers: List[RouterType] = list()
    for router in iqa.routers:
        routers.append(router.node.hostname)

    # Broker queues
    broker_queues: List[str] = [
        'brokeri2.durable.queue', 'brokeri2.nondurable.queue',
        'brokere3.durable.queue', 'brokere3.nondurable.queue',
        'interior.autolink.durable.queue',
        'interior.autolink.nondurable.queue', 'edge.autolink.durable.queue',
        'edge.autolink.nondurable.queue'
    ]

    # Address translation tuple
    address_translation_tuple: List[Tuple[str, str, str]] = [
        ('addremoveprefix.durable.queue', 'brokeri2.durable.queue',
         'Broker.M.I2'),
        ('durable.queue', 'brokeri2.durable.queue', 'Broker.M.I2'),
        ('removeprefix.brokeri2.durable.queue', 'brokeri2.durable.queue',
         'Broker.M.I2'),
        ('edgeremove.durable.queue', 'brokere3.durable.queue', 'Broker.M.E3')
    ]
    address_translation_fixtures: List[str] = [
        'address', 'translates_to', 'broker'
    ]

    # Broker durable topics
    broker_durable_topics: List[Tuple[str, str]] = [
        ('brokeri2.durable.topic', 'Broker.M.I2'),
        ('brokere3.durable.topic', 'Broker.M.E3')
    ]
    # Broker non-durable topics
    broker_nondurable_topics: List[Tuple[str, str]] = [
        ('brokeri2.nondurable.topic', 'Broker.M.I2'),
        ('brokere3.nondurable.topic', 'Broker.M.E3')
    ]

    if any([v for v in metafunc.fixturenames
            if v in ['sender', 'get_sender']]):
        metafunc.parametrize('sender', senders_comb, indirect=True)

    if any([
            v for v in metafunc.fixturenames
            if v in ['receiver', 'get_receiver']
    ]):
        metafunc.parametrize('receiver', receivers_comb, indirect=True)

    if 'router' in metafunc.fixturenames:
        metafunc.parametrize('router', routers, indirect=True)

    if 'router_edge' in metafunc.fixturenames:
        metafunc.parametrize('router_edge',
                             [r for r in routers if r.startswith('Router.E')],
                             indirect=True)

    if 'router_interior' in metafunc.fixturenames:
        metafunc.parametrize('router_interior',
                             [r for r in routers if r.startswith('Router.I')],
                             indirect=True)

    if 'router_with_broker' in metafunc.fixturenames:
        metafunc.parametrize('router_with_broker', ['Router.I2', 'Router.E3'],
                             indirect=True)

    if 'broker_master' in metafunc.fixturenames:
        metafunc.parametrize('broker_master', ['Broker.M.I2', 'Broker.M.E3'],
                             indirect=True)

    if 'broker_slave' in metafunc.fixturenames:
        metafunc.parametrize('broker_slave', ['Broker.S.I2', 'Broker.S.E3'],
                             indirect=True)

    if 'queue' in metafunc.fixturenames:
        metafunc.parametrize('queue', broker_queues)

    # If all fixture names defined in address_translation_fixtures exist in metafunc.fixturenames
    address_translation_fixtures_count = len([
        f for f in address_translation_fixtures if f in metafunc.fixturenames
    ])
    if address_translation_fixtures_count == len(address_translation_fixtures):
        metafunc.parametrize('address,translates_to,broker',
                             address_translation_tuple)

    if {'topic_durable', 'broker'}.issubset(metafunc.fixturenames):
        metafunc.parametrize('topic_durable,broker', broker_durable_topics)

    if {'topic_nondurable', 'broker'}.issubset(metafunc.fixturenames):
        metafunc.parametrize('topic_nondurable,broker',
                             broker_nondurable_topics)