[Python] "Testing my twttr" error with check50 - CS50P PSET 5

Discussão em 'Python' iniciado por Stack, Abril 24, 2025.

  1. Stack

    Stack Membro Participativo

    Goal is to test twttr.py with test_twttr.py

    twttr.py:

    def main():

    user = str(input("Input: "))

    print(shorten(user))


    def shorten(word):
    word = str(word)
    result = ''

    vowels = ['a', 'e', 'i', 'o', 'u']

    for letter in word:
    if letter.lower() not in vowels:
    result += letter

    return result


    if __name__ == "__main__":
    main()


    test_twttr.py:

    from twttr import shorten

    def test_default():
    assert shorten("") == ""

    def test_uCase():
    assert shorten("twITter") == "twTtr"

    def test_lCase():
    assert shorten("TWitTER") == "TWtTR"

    def test_int():
    assert shorten(0) == "0"
    assert shorten(452) == "452"
    assert shorten("21") == "21"

    def test_float():
    assert shorten(3.14) == "3.14"
    assert shorten("2.71e") == "2.71"

    def test_punc():
    assert shorten("..,-!?ab:i") == "..,-!?b:"


    Getting this error with check50 even though all tests passed in pytest: [​IMG]

    :) test_twttr.py exist
    :( correct twttr.py passes all test_twttr checks
    expected exit code 0, not 1
    :| test_twttr catches twttr.py without vowel replacement
    can't check until a frown turns upside down
    :| test_twttr catches twttr.py without capitalized vowel replacement
    can't check until a frown turns upside down
    :| test_twttr catches twttr.py without lowercase vowel replacement
    can't check until a frown turns upside down
    :| test_twttr catches twttr.py omitting numbers
    can't check until a frown turns upside down
    :| test_twttr catches twttr.py printing in uppercase
    can't check until a frown turns upside down
    :| test_twttr catches twttr.py omitting punctuation
    can't check until a frown turns upside down


    When self checking code with pytest all tests pass but when check50 uses pytest it returns exit code 1. My guess is that this is due to check50 having its own "correct" version of twttr.py on which it uses my test_twttr.py.

    Continue reading...

Compartilhe esta Página