nteract / testbook

🧪 📗 Unit test your Jupyter Notebooks the right way
https://testbook.readthedocs.io
BSD 3-Clause "New" or "Revised" License
416 stars 37 forks source link

Raise an error if the accessed value is not defined #96

Closed aakashns closed 3 years ago

aakashns commented 3 years ago

When I try:

tb["happy_fraction"]

And the name happy_fraction is not defined, it would be useful to raise an error with the message 'happy_fraction' is not defined in the notebook

On the other hand:

tb.get('happy_fraction')

can return None (similar to how .get works for dictionaries)

Also, it would be nice if the following check is supported:

# Checks if the variable/function `happy_fraction` is defined
'happy_fraction' in tb
aakashns commented 3 years ago

I think right now the error is:

testbook.exceptions.TestbookExecuteResultNotFoundError: code provided does not produce execute_result

which is a bit confusing (I didn't realize that this error was thrown when I was trying to access a variable that did not exit)

rohitsanj commented 3 years ago

That is not the expected behaviour - It should ideally throw a TestbookRuntimeError which contains an attribute called eclass containing the actual error class raised in the notebook. For example, in the case of a variable/function not being found, e.class would be NameError.

Can you please provide some more context?

Also, it would be nice if the following check is supported: 'happy_fraction' in tb

Sure, will create an issue for that right away :)