Describe the bug
Having any multiline statement in test cells lead to a test failure because of unmatched parenthesis although the code works fine when executed in the Jupyter Notebook.
For example, a test that looks like this:
assert y.find(
'a'
) == 1
Will work fine in Jupyter and with otter assign
, but when doing otter run
it will throw the following error:
/home/joel/miniconda3/envs/573/lib/python3.10/site-packages/nbformat/__init__.py:128: MissingIDFieldWarning: Code cell is missing an id field, this will become a hard error in future nbformat versions. You may want to use `normalize()` on your notebooks before validations (available since nbformat 5.1.4). Previous versions of nbformat are fixing this issue transparently, and will stop doing so in the future.
validate(nb)
Traceback (most recent call last):
File "/home/joel/miniconda3/envs/573/bin/otter", line 8, in <module>
sys.exit(cli())
File "/home/joel/miniconda3/envs/573/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/home/joel/miniconda3/envs/573/lib/python3.10/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/home/joel/miniconda3/envs/573/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/joel/miniconda3/envs/573/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/joel/miniconda3/envs/573/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/home/joel/miniconda3/envs/573/lib/python3.10/site-packages/otter/cli.py", line 32, in wrapper
return f(*args, **kwargs)
File "/home/joel/miniconda3/envs/573/lib/python3.10/site-packages/otter/cli.py", line 65, in assign_cli
return assign(*args, **kwargs)
File "/home/joel/miniconda3/envs/573/lib/python3.10/site-packages/otter/assign/__init__.py", line 177, in main
run_tests(
File "/home/joel/miniconda3/envs/573/lib/python3.10/site-packages/otter/assign/utils.py", line 216, in run_tests
raise RuntimeError(f"Some autograder tests failed in the autograder notebook:\n" + \
RuntimeError: Some autograder tests failed in the autograder notebook:
q1 results:
q1 - 1 result:
❌ Test case failed
Trying:
assert y.find(
'a'
Expecting nothing
**********************************************************************
Line 1, in q1 0
Failed example:
assert y.find(
'a'
Exception raised:
Traceback (most recent call last):
File "/home/joel/miniconda3/envs/573/lib/python3.10/doctest.py", line 1350, in __run
exec(compile(example.source, filename, "single",
File "<doctest q1 0[0]>", line 1
assert y.find(
^
SyntaxError: '(' was never closed
Trying:
) == 1
Expecting nothing
**********************************************************************
Line 3, in q1 0
Failed example:
) == 1
Exception raised:
Traceback (most recent call last):
File "/home/joel/miniconda3/envs/573/lib/python3.10/doctest.py", line 1350, in __run
exec(compile(example.source, filename, "single",
File "<doctest q1 0[1]>", line 1
) == 1
^
SyntaxError: unmatched ')'
To Reproduce
Setup a notebook question with a test cell that has multiple lines, e.g.
Expected behavior
It is useful to be able to split code over mutliple lines to make it more readable when doing method chaining and similar, so it would be great it this did not lead to an error, but worked since it is valid Python syntax.
Versions
Otter 4.2.0 Python 3.10.x
bug