Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

HW4rec - Unexpected forbiddenError during testing

R
Roberta Iapichello (140 points)
0 1 3
in HW4 by (140 points)
I uploaded the file for the hw4rec, but two of the tests carried out fail. the error is forbiddenError, the description of which is given below:
testlib.ForbiddenError = The import of 'py._io.terminalwriter' is forbidden
i checked the code over and over again, and there is no print statement in it (everything required is printed in a text file)

1 Answer

andrea.sterbini (207940 points)
756 1270 2377
by (208k points)
Appena posso ci guardo
andrea.sterbini (207940 points)
756 1270 2377
by (208k points)

It seems that you get a timeout error, but to print that error pytest wants to import terminalwriter, and this is the error that is shown.
If you look at the error stacktrace you can notice the timeout function 

test_01.py=37= in do_test
    result = func(*params)
program01.py=283= in print_top_students
    matricole_studenti_brillanti = top_students(dbsize)
program01.py=211= in top_students
    studenti = [ studente for studente in studenti if student_average(studente['stud_code'], dbsize) >= 28]
program01.py=211= in 
    studenti = [ studente for studente in studenti if student_average(studente['stud_code'], dbsize) >= 28]
program01.py=122= in student_average
    esami = list(filter(lambda esame= esame['stud_code'] == stud_code, esami))
program01.py=122= in 
    esami = list(filter(lambda esame= esame['stud_code'] == stud_code, esami))
/home/andrea/miniconda3/lib/python3.8/site-packages/pytest_timeout.py=447= in write_title
    width = py.io.get_terminal_width()
/home/andrea/miniconda3/lib/python3.8/site-packages/py/_vendored_packages/apipkg/__init__.py=152= in __makeattr
    result = importobj(modpath, attrname)
/home/andrea/miniconda3/lib/python3.8/site-packages/py/_vendored_packages/apipkg/__init__.py=72= in importobj
    module = __import__(modpath, None, None, ['__doc__'])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = ('py._io.terminalwriter', None, None, ['__doc__']), kargs = {}
name = 'py._io.terminalwriter', rest = [None, None, ['__doc__']]

    def _check_import(*args, **kargs)=
        name, *rest = args
        if name in forbidden or (not forbidden and name not in allowed)=
            print(f"Importing {name} (globals, locals, {rest[-2=]}) (not allowed)")
>           raise ForbiddenError(f"The import of '{name}' is forbidden")
E           testlib.ForbiddenError= The import of 'py._io.terminalwriter' is forbidden

andrea.sterbini (207940 points)
756 1270 2377
by (208k points)
To solve this you could improve the algorithm to be faster
R
Roberta Iapichello (140 points)
0 1 3
by (140 points)
I hadn't noticed this detail. thanks