1

For PS5 - Back to the Bank, the unit test script works when I run it on code50, however, when I run the check50 I am getting expected exit code 0, not 1. If anyone has a suggestion, I would greatly appreciate.

Here is the check on code50:

test_bank/ $ pytest test_bank.py 
============================================================ test session starts ============================================================
platform linux -- Python 3.10.4, pytest-7.1.2, pluggy-1.0.0
rootdir: /workspaces/103697464/test_bank
collected 6 items                                                                                                                           

test_bank.py ......                                                                                                                   [100%]

============================================================= 6 passed in 0.11s =============================================================

Here is the result with check50:

Results for cs50/problems/2022/python/tests/bank generated by check50 v3.3.6

:) test_bank.py exist  
:( correct bank.py passes all test_bank checks
    expected exit code 0, not 1    
:| test_bank catches bank.py with incorrect values
    can't check until a frown turns upside down    
:| test_bank catches bank.py without case-insensitivity
    can't check until a frown turns upside down    
:| test_bank catches bank.py not allowing for entire phrase
    can't check until a frown turns upside down

Here are the scripts:

  • test_bank.py
try:
    from test_bank.bank import value
except:
    from bank import value

def test_hello():
    assert value("hello") == "$0"

def test_hello_upper():
    assert value("HELLO") == "$0"

def test_h_preceding():
    assert value("hard") == "$20"

def test_h_preceding_upper():
    assert value("HARD") == "$20"

def test_else():
    assert value("bla") == "$100"

def test_else_upper():
    assert value("BLA") == "$100"
  • bank.py
def main():
    print(value(input("Greeting: ").lower().lstrip()))

def value(greeting):
    if greeting[0:5].lower() == "hello":
        return "$0"
    elif greeting[0].lower() == "h":
        return "$20"
    else:
        return "$100"

if __name__ == "__main__":
    main()

1 Answer 1

8

This has been discussed on the CS50 ED Discussion Forums. Have you reviewed them? The first check is running your tests against their test "correct version" of bank.py (not your version). So, 1 or more of your tests fails when it calls that version (not your version)

Re-read the instructions, specifically: "restructure your code, where value() expects a str as input and returns 0 (as an int)"

6
  • Thank you very much. I'll check the discussion forums. I checked others but not that one.
    – Jean-Marc
    May 16, 2022 at 20:12
  • Start by re-reading the instructions I include above and checking your code. Your version of bank.py is not returning an int. That's why your code "passes" and it fails with check50. you are asserting the wrong value.
    – kcw78
    May 17, 2022 at 0:03
  • Yes. Thank you. I fixed them all in the PS5.
    – Jean-Marc
    May 17, 2022 at 0:32
  • I lstriped the input string in bank.py, so add a test for that. Removing that test from the test_bank.py fixed the issue. Your answer helped me understand why this didn't work. Thank you!
    – ali b
    Jul 1, 2022 at 17:05
  • Thanks a lot @kcw78 Jul 11, 2022 at 12:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .