Closed ranjiGT closed 2 years ago
Hi @ranjiGT! Thanks for raising this bug! This was a simple fix, and I'll be raising a PR soon. :)
Meanwhile, you could consider using the with testbook(..) as tb
pattern instead of the decorator pattern.
from testbook import testbook
def test_stdout(tb):
cells = [7, 13, 17, 21]
score = 0
with testbook('./ssnn_solved.ipynb', execute=True):
for cell in cells:
if tb.cell_output_text(cell) == 'Test passed.':
score += 1
return score
res = test_stdout()
print(res)
Hi @rohitsanj, it now works
I believe the code should be :
from testbook import testbook
def test_stdout():
cells = [7, 13, 17, 21]
score = 0
with testbook('./ssnn_solved.ipynb', execute=True) as tb:
for cell in cells:
if tb.cell_output_text(cell) == 'Test passed.':
score += 1
return score
res = test_stdout()
print(res)
Because def test_stdout(tb)
takes tb as object and gives TypeError: test_stdout() missing 1 required positional argument: 'tb'
Thanks!
Yep, that's right! My bad :)
I am writing a code for auto-grading my notebook based on the test_stdout() example. It successfully checks the conditions as defined by
tb.cell_output_text()
but when I perform some basic operations the return value is None is what I get, instead of the variable that I pass into this function.Note: The below I call from a external python file to execute my notebook.
Outputs : None
But desired: 4