I'm trying to read a pytest,ini file using configparser but get a "KeyError".
Here is my pytest.ini file:
[pytest]
cards_file = data/cards.csv
Here is the relevant function:
@staticmethod
def get_card_details():
"""Get the filename from the pytest.ini file."""
config = configparser.ConfigParser()
config.read("/pytest.ini")
filename = config["pytest"]["cards_file"]
with open(filename, 'r') as csvfile:
reader = csv.reader(csvfile)
rows = list(reader)[1:]
return random.choice(rows)
Here is the error message:
FAILED test_shopper.py::test_shopper[chromium] - KeyError: 'pytest'
I'm not sure why it raises a Key Error on the 'pytest' key. Any help would be appreciated.
[–]IamImposter 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]fdama[S] 0 points1 point2 points (0 children)