cs50 / problems

Checks for check50
134 stars 227 forks source link

CS50P Problem Set 8 - test_jar - check50 method `test_number_functions()` may fail on test counts larger than 9 and ending with 3 or less #247

Closed kguryanov closed 1 month ago

kguryanov commented 2 months ago

Steps to reproduce:

  1. Create 23 tests in your test_jar.py
  2. Run check50 cs50/problems/2022/python/jar

Actual result:

  1. check50 fails for the last test ":( test_jar.py contains at least four functions".

    image

Expected result:

  1. check50 validation must succeed since the problem set requirement is satisfied.

    image

Possible solution:

  1. Add + token to the regex expression matches = re.search(r'(\d+) passed', out):

    image

NOTES:

The regex for parsing pytest output - matches = re.search(r'(\d) passed', out) - only captures 1 digit in the capturing group:

image

The number of test is parsed into variable and is checked against expected number of 4 test functions:

    if not matches:
        raise check50.Failure("Could not parse output of pytest")
    try:
        functions = int(matches.groups(1)[0]) # save number of tests
    except ValueError:
        raise check50.Failure("Could not parse output of pytest")
    if functions < 4:  # do the validation
        raise check50.Failure("test_jar.py does not contain at least four functions")

So, pset test file with 23 tests will fail the validation since capturing group only catches the "3 passed" part of string "= 23 passed in 0.03s =":

Workaround

In case you have more that 9 tests, make sure you have test counts are in range [14 .. 19], [24 .. 29], etc.:

patrickthornton commented 1 month ago

right you are; should be fixed by https://github.com/cs50/problems/pull/262!