0

mo code works fine and passes al teat in test_working.py but i dont know why i get this error

:) working.py and test_working.py exist
:) working.py does not import libraries other than sys and re
:) working.py converts "9 AM to 5 PM" to "09:00 to 17:00"
:) working.py converts "9:00 AM to 5:00 PM" to "09:00 to 17:00"
:) working.py converts "8 PM to 8 AM" to "20:00 to 08:00"
:) working.py converts "8:00 PM to 8:00 AM" to "20:00 to 08:00"
:) working.py converts "12 AM to 12 PM" to "00:00 to 12:00"
:) working.py converts "12:00 AM to 12:00 PM" to "00:00 to 12:00"
:) working.py raises ValueError when given "8:60 AM to 4:60 PM"
:) working.py raises ValueError when given "9AM to 5PM"
:) working.py raises ValueError when given "09:00 to 17:00"
:) working.py raises ValueError when given "9 AM - 5 PM"
:( correct working.py passes all test_working checks
    expected exit code 0, not 1
:| test_working.py catches working.py printing incorrect hours
    can't check until a frown turns upside down
:| test_working.py catches working.py printing incorrect minutes
    can't check until a frown turns upside down
:| test_working.py catches working.py not raising ValueError when user omits " to "
    can't check until a frown turns upside down
:| test_working.py catches working.py not raising ValueError for out-of-range times
    can't check until a frown turns upside down
:| test_working.py catches working.py not raising ValueError for invalid time format
    can't check until a frown turns upside down

3 Answers 3

6

This scenario has been described in the CS50 Python ED forum. When you get this error message:

:( correct working.py passes all test_working checks
    expected exit code 0, not 1

It means check50 is running your test_working.py against their correct version of working.py. Error code 1 means at least one of your assert statements fails when it shouldn't. You need to find out which one is incorrect. The best approach is to test with 1 assert statement. If it passes, add another assert. Continue until you find the assert that fails. Good luck.

3
  • Thanks for the help
    – Ehsan_hrz
    Jun 4, 2022 at 7:05
  • Helped me as well. Thank you very much! couldn't understand what's wrong :)
    – Jonathan.
    Jun 17, 2022 at 15:58
  • Thanks for the help. In my case I did an extra function and I was testing it in my test_working.py but obviusly they don´t have it in their own version of working.py. The solution was to remove that part of the testing.
    – esceli
    Dec 13, 2022 at 14:37
1

For the last two errors you can solve them with this code:

def test_wrong_format():
    with pytest.raises(ValueError):
        convert("9 AM - 9 PM")


def test_wrong_minute():
    with pytest.raises(ValueError):
        convert("9:60 AM to 9:60 PM")


def test_wrong_hour():
    with pytest.raises(ValueError):
        convert("13 PM to 17 PM")

Hope it helps :)

0

For me the issue was that I had the following test in my test_working.py:

assert convert("0 AM to 0 PM") == "00:00 to 12:00"

which actually worked using my working.py but I it technically shouldn't be valid input.

I decided to just throw a ValueError if the entry is 0.

You must log in to answer this question.

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