ForbiddenError after submitting the homework

GabrielAlexandru (7760 points)
2 4 29
asked Oct 20, 2021 in HW1 optional by GabrielAlexandru (7,760 points)

Hey, I submitted the Homework earlier today. In my local machine every test passed.

In the virtual machine one test didn't pass though. I thought my program exceeded the maximum time, but after scrolling a couple of times in the "results" console I found this error:

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

name = 'py._io.terminalwriter' 

def _check_import(*args, **kargs)= 

name = args[0] 

if name in forbidden or (not forbidden and name not in allowed)= 

print(f"Importing {name} ({kargs}) (not allowed)") 

> raise ForbiddenError(f"The import of '{name}' is forbidden") 

E testlib.ForbiddenError= The import of 'py._io.terminalwriter' is forbidden 

testlib.py=42= ForbiddenError

I searched on this website and found that a similar error happened last year in the Italian course here.

So, I was wondering if it's a problem of my code or not.

P.S. I have yet to experiment how the forum works, so I apologise if the question's style isn't pretty.

142 views

2 Answers

Best answer
gianluca5539 (9820 points)
3 6 44
answered Oct 21, 2021 by gianluca5539 (9,820 points)
selected Oct 21, 2021 by GabrielAlexandru

I think it's a timeout. As you can see in line 25 of the log you shared:

/usr/lib/python3/dist-packages/pytest_timeout.py=382= in write_title

 I downloaded the pytest_timeout library to check what was happening in line 382, and this is what I found out:

pytest.fail("Timeout >%ss" % timeout)

Maybe you have a very powerful machine that runs that code fast enough to pass the test, I don't know, but from what I can see it looks like a timeout error. 

GabrielAlexandru (7760 points)
2 4 29
commented Oct 21, 2021 by GabrielAlexandru (7,760 points)
So, now another question arise: why it is shown as ForbiddenError instead of TimeoutError? I know though there's  nothing we can do as the execution happens on a virtual machine we can't access.

Hopefully someone can confirm that the error it's actually a timeout. Thank you for your time!
andrea.sterbini (172680 points)
511 927 1776
commented Oct 21, 2021 by andrea.sterbini (172,680 points)
I think the pytest machinery tries to import a module when showing the timeout error and this is what caught your eye.

I will have a look at simplifying the output or the tests to avoid such additional error message
gianluca5539 (9820 points)
3 6 44
answered Oct 21, 2021 by gianluca5539 (9,820 points)

Did you import any libraries that you then forgot to remove? Like to track time for example.

Note that no libraries are allowed for this exercise. 

raise ForbiddenError(f"The import of '{name}' is forbidden")

GabrielAlexandru (7760 points)
2 4 29
commented Oct 21, 2021 by GabrielAlexandru (7,760 points)
I didn't import any library. Every other test worked fine.

The error was raised only in one test.
gianluca5539 (9820 points)
3 6 44
commented Oct 21, 2021 by gianluca5539 (9,820 points)
I think there is an error, it looks like pytest is trying to use terminalwriter to display the error message. Can you paste the full logs of the pytest in a pastebin or something? Thank you
GabrielAlexandru (7760 points)
2 4 29
commented Oct 21, 2021 by GabrielAlexandru (7,760 points)

Here is the failure log.

gianluca5539 (9820 points)
3 6 44
commented Oct 21, 2021 by gianluca5539 (9,820 points)
I think I know what happened, I will post another answer.