I want to test the following function with pytest:
def createDF(path):
df = pd.DataFrame()
try:
data = pd.read_csv(path, sep='\t')
#print(data)
df = pd.DataFrame(data)
return df
except pd.errors.EmptyDataError:
logging.exception("CSV File Empty")
sys.exit(0)
it shall except when reading in a empty csv and then exit.
The test looks like this. I iterated over a couple of csv files with the fixture. One of the files is empty so the SystemExit is raised in the test.
@pytest.mark.parametrize("csvs",glob.glob("./data/*"))
def test_parser(csvs, capsys):
"""
Checking if table is empty
"""
df = pd.DataFrame()
df=createDF(csvs)
assert df.empty is False
print("\nRunning createDF:", df.empty)
One test is failing with SystemExit exception but it shall not fail as its desired behavior
This case is not working for me because the other files in the fixture not raising the exception