Python Forum

Full Version: How to run a pytest test for each item in a list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I have the below pytest code as part of DSS. In general it's really simple: It gets list of scenarios:
https://github.com/dataiku/dataiku-api-c...io.py#L651

and checks for the ones who starts with the word TEST

import dataikuapi

import pytest

def test_check_scenario_exist(params):

    client = dataikuapi.DSSClient(params['host'], params['api'])

    client._session.verify = False

    project = client.get_project(params['project'])

    scenarios = project.list_scenarios()

    test_scenario = False

    for scenario in scenarios:

        if scenario["name"].startswith("TEST"):

            test_scenario = True

    assert test_scenario, "You need at least one test scenario (name starts with 'TEST_')"
The problem is in case there are more than one scenario, it is still consider it as one test, and I want to treat each item in the list as a single test, so at the end I will get 2 results (assuming I had 3 scenarios and 2 of them starts with TEST).
I tried to follow these threads, but no luck:
https://stackoverflow.com/questions/56754769/how-to-run-a-pytest-test-for-each-item-in-a-list-of-arguments

https://stackoverflow.com/questions/59984934/how-to-test-all-elements-from-a-list


any suggestions on how to implement it correctly?