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
  Pytest Installed, but VS Code Won’t Access Pytest AstralWeeks 9 2,887 Sep-13-2023, 03:00 PM
Last Post: AstralWeeks
  Pytest mocks anthonyrmoss78 0 426 May-30-2023, 08:28 PM
Last Post: anthonyrmoss78
  How to sort .csv file test log which item first fail and paint color SamLiu 24 4,702 Sep-03-2022, 07:32 AM
Last Post: Pedroski55
  Membership test for an element in a list that is a dict value for a particular key? Mark17 2 1,159 Jul-01-2022, 10:52 PM
Last Post: Pedroski55
Question Finding string in list item jesse68 8 1,799 Jun-30-2022, 08:27 AM
Last Post: Gribouillis
  how to easily create a list of already existing item CompleteNewb 15 3,379 Jan-06-2022, 12:48 AM
Last Post: CompleteNewb
  Remove an item from a list contained in another item in python CompleteNewb 19 5,548 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  count item in list korenron 8 3,372 Aug-18-2021, 06:40 AM
Last Post: naughtyCat
  How to test and import a model form computer to test accuracy using Sklearn library Anldra12 6 3,064 Jul-03-2021, 10:07 AM
Last Post: Anldra12
  Time.sleep: stop appending item to the list if time is early quest 0 1,846 Apr-13-2021, 11:44 AM
Last Post: quest

Forum Jump:

User Panel Messages

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