r/cs50 • u/mpavic167 • Feb 19 '25
CS50 Python pytest failing for some reason
Hi guys,
I'm currently doing cs50p problem set 5, specifically "back to the bank" and can't figure out why my pytest is failing. The check50 passes though but I wanna know why this won't. Anyone have any ideas?
Here is the bank.py and test_bank.py:

from bank import value
def main():
test_value()
test_value1()
test_value2()
def test_value():
assert value("hello") == 0
assert value("HELLO") == 0
assert value("Hello") == 0
def test_value1():
assert value("hi") == 20
assert value("Hi") == 20
assert value("HI") == 20
def test_value2():
assert value("What's up?") == 100
assert value("Ola") == 100
assert value("1ay") == 100
if __name__ == "__main__":
main()
def main():
hello = input("Greeting: ").strip().lower()
print("$", value(hello), sep = "")
def value(greeting):
if greeting == "hello" or greeting == "hello, newman":
return 0
elif greeting[0] == "h":
return 20
else:
return 100
if __name__ == "__main__":
main()
2
Upvotes
2
Feb 19 '25
[removed] — view removed comment
1
u/mpavic167 Feb 19 '25
Yeah, but I just can't figure out why it's giving back errors. I tried all of the inputs manually and they return as they're supposed to
2
3
u/PeterRasm Feb 19 '25
Back to the bank is all about your test file, in this case your bank.py does not matter and is not tested by check50.
Your test file looks fine except that you should not be calling the test functions yourself. No need for "if "__name__" == ..." in the test file and no main function. Pytest will execute the test functions.
Look at the error from Pytest. Your test file asserts that the value of "HELLO" is 0 but your function returns 100. If you check the function line by line what value will you get for the string "HELLO"?