Unitests.py fails when executed locally

I want to save the grade exercise notebook and being able to execute it locally, but when I run the cells with the tests I get the following error message:

AttributeError: Can’t pickle local object ‘test_shortest_path..g..helper’

Does anyone know how to fix this error?

Thanks,

Antonio

You have to install the same versions of all of the packages that Coursera’s environment uses.

Thanks.

I created a requirements.txt file using this script:

import pkg_resources

with open(‘requirements.txt’, ‘w’) as f:
for package in pkg_resources.working_set:
f.write(f"{package.key}=={package.version}\n")

1 Like

After recreating the coursera environment I get the following error:

AttributeError: Can’t get local object ‘test_shortest_path..g..helper’

Is this for the lab titled “Implementing graph algorithms with LLMs” ?

The “test_shortest_path()” function is defined in unittests.py.
It defines both the “g()” function and the "helper() function.

Did you download and install the unittest.py file?

Yes. I downloaded all the files including those in the data folder.

I try debugging with an LLM and the reply was that the helper function should not be defined inside the g function in order to use pickle for multiprocessing.

Although this answer is consistent with what I saw in several web posts, it doesn’t explain why it works on the coursera hosted environment.

Sorry, I don’t understand it either.

That is OK. Thank you.