pytest functions don’t return data to be used in following functions in the same pytest file?

  pytest, python

I have developed a program (file.py) formed by a few functions and now I want to test each of these functions. I have tested the first function correctly but when I have wanted to test the second function I have noticed that I need the data generated from the first function. What is the best way to do this?

My first attend has been this

def test_load_sample():  # The first test for the first function
    '''Verify all rows of the body of the vcf file are taken'''
    data_to_test = load_sample (NAME_FILE_1) # load_sample() is the first function of file.py
    return data_to_test     # I need this data for the following tests
    assert len(data_to_test) == 1400
    

data_to_test = data_to_test

Because I expected that the function test_load_sample would return the data I want for the second test. However, it seems that pytest function doesn’t return what has been tested?

What is the best way to do this? Am I doing something wrong? This is my first time working with pytest.

Source: Python Questions

LEAVE A COMMENT