pytestfilenotfounderror

pytest does not pass the test


file_workers.py

def read_from_file(filepath):
    with open(filepath, 'r') as f_o:
        return f_o.readlines()

test_file_workers.py

from my_funcs.file_workers import read_from_file


def test_read_from_file():
    test_data = ['one\n', 'two\n','three\n']
    assert test_data == read_from_file('testfile.txt')

testfile.txt

one
two
three

I've tried everything but the test doesn't pass

The test must passenter image description here


Solution

  • I think that it's because test_data is a list (and what you're comparing it to is not a list)? I'd say try a string instead.