Python Forum
How to run a pytest test for each item in a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to run a pytest test for each item in a list
#1
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?
Kakha likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to test and import a model form computer to test accuracy using Sklearn library Anldra12 6 405 Jul-03-2021, 10:07 AM
Last Post: Anldra12
  count item in list korenron 7 283 Jul-01-2021, 01:46 PM
Last Post: deanhystad
  Time.sleep: stop appending item to the list if time is early quest 0 357 Apr-13-2021, 11:44 AM
Last Post: quest
  How do I add a number to every item in a list? john316 2 433 Oct-28-2020, 05:29 PM
Last Post: deanhystad
  Ignoring a list item hank4eva 2 714 Aug-17-2020, 08:40 AM
Last Post: perfringo
  Select correct item from list for subprocess command pythonnewbie138 6 905 Jul-24-2020, 09:09 PM
Last Post: pythonnewbie138
  pytest, parametrize, neasted list niski1996 0 460 Jul-21-2020, 10:36 PM
Last Post: niski1996
  Why is the item not in list when it is DanielCook 2 656 Jul-08-2020, 07:38 PM
Last Post: deanhystad
  Pytest and rootdirectory Master_Sergius 4 940 Jun-01-2020, 05:05 PM
Last Post: Master_Sergius
  best way to add item to list only once Phaze90 1 788 May-01-2020, 05:02 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020