I wrote code in python 3, and want to write tests to my code using the Pytest framework. I have one function (the main function) that gets input from the user(a file name), processes it and prints a result to the screen(the answer can be true or false). How can I write a test function that inputs data by herself(for the main input) and check what printed to the console? (I use Pycharm)
def main():
file_input = input(str('path to your file here'))
with open(file_input, mode="r") as f:
for line in f:
reader = line.split()
# Convert to boolean <-- Not working?
flag = bool(reader[0])
if flag:
print('flag == True')
else:
print('flag == False')
if __name__ == '__main__':
main()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.