Closed superstar54 closed 4 months ago
The difference is in how the parser
function is pickled by dill
. When running through pytest
, it is pickled as <function run_pickle.test_shell.<locals>.parser(self, dirpath)>
. But when running the script directly, it is stored as <function __main__.test_shell.<locals>.parser(self, dirpath)>
. Notice that in the latter case, the "module" is __main__
because the script is the main entry point. However, when running through pytest, the script is treated as a module and so the module string starts with run_pickle
(which is the name I gave to the script).
When dill tries to unpickle the pytest case, it will try to load the run_pickle
module, but this is likely not in the path and so it fails.
I don't think this is a bug in aiida-shell
. Why are you running a script through pytest
? If you want to write unit tests that include a dynamic parser using pytest
, you can see how it is done here: https://github.com/sphuber/aiida-shell/blob/f68ea013a7392bb0000b85bc6a266f7dce694cf1/tests/test_launch.py#L272
That works just fine. Closing this for now. Feel free to reopen if you think there still is a problem in functionality
Thanks for the comment. I used it in the unit test, and I think I did the same as in the aiida-shell/test_launch.py. I will investigate it more and will reopen it if needed.
Here is the script to reproduce
Run
pytest test_shell.py
, the process is exceptedHowever, if I run
test_shell()
function directly inside the script usingpython test_shell.py
instead ofpytest
, it works without error.