Faced such complexity to generate test data in pytest. I read the key-value pair from a text file (json), and with the help of yield I pass it to the pytest fixture as follows:
def read_list(): with open(config.testfile) as f: data = json.load(f) dct = {line['fullname']: line['val'] for line in data} for res in dct: yield res, dct[res] @pytest.mark.parametrize('name, val', read_list()) def test_task_waiting(driver, name, val): assert create_task(driver, name, val) The problem is that when you restart, the test is run by the parameters in the same order in which they are in the original json file. How can I apply a random element from the dct dictionary to the input of the test function? I tried random.choice, but it returns a random value only once, the task failed with the fly.