0

On pset 5, I am getting this error from check50:

:( correct plates.py passes all test_plates checks
    expected exit code 0, not 2

I am confused because my plates.py does pass all test_plates checks:

$ pytest test_plates.py
================================ test session starts ================================
platform linux -- Python 3.10.9, pytest-7.2.1, pluggy-1.0.0
rootdir: /home/atsaloli/git/atsaloli/learn-python/cs50p-me50/test_plates
collected 4 items

test_plates.py ....                                                           [100%]

================================= 4 passed in 0.01s =================================
$

Seems like the same issue as check50 gives "correct working.py passes all test_working checks expected exit code 0, not 2" when "pytest test_working.py" works

Here is my test code:

from plates import *
#from plates import is_valid

def test_is_two_to_six_chars_long():
    # vanity plates may contain a maximum of 6 characters (letters or
    # numbers) and a minimum of 2 characters.
    assert is_valid('A') == False
    assert is_valid('AB') == True
    assert is_valid('ABCCCCCCCCCCC') == False

def test_first_two_chars_are_letters():
    # vanity plates must start with at least two letters.
    assert is_valid('AB123') == True
    assert is_valid('123456') == False

def test_contains_illegal_character():
    # No periods, spaces, or punctuation marks are allowed.
    # ASCII 65-90 are uppercase letters which are the only allowed characters
    assert is_valid('AB.123') == False
    assert is_valid('AB12 3') == False
    assert is_valid('ABC123') == True
    assert is_valid('AbC123') == False

def test_contains_letters_after_numbers():
    # Numbers cannot be used in the middle of a plate; they must come
    # at the end. The first number used cannot be a ‘0’
    assert is_valid('ABC123') == True
    assert is_valid('ABC0123') == False
    assert is_valid('ABC23DE') == False

if __name__ == "__main__":
    main()

1 Answer 1

0

I had success by implementing test functions with names that were descriptive and then including 1 or 2 assert statements. I wasted a lot of time on this.

Try function names like: test_is_valid_alphanumeric()

You must log in to answer this question.

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