sashgorokhov / jupyter-pytest-2

Write and run pytest tests in your notebook! Why? Because you can!
3 stars 2 forks source link

Question about the "left hand side" of the assert #1

Open connorferster opened 3 years ago

connorferster commented 3 years ago

Hi there!

I have been looking for a library like this for a couple of years! And now I have found it! Thank you! So simple but so perfect.

I am teaching a Python course centered around Jupyter Notebooks and I would love to get the new students learning how to use pytest right from the time they learn how to write functions. jupyter-pytest-2 is the perfect thing. I am hoping you can address the following two minor issues that I am having:

  1. If I run pytest.main() in the test cell, without any arguments as shown on your README.md, then it generates an error: image

  2. In the notebook, the term on the left of the assert is not evaluated in the print to stdout, as is shown on the pytest website. I have tried using various flags (e.g. -v and -l) but I am still not seeing anything on this failing test: image

Thank you very much for any assistance you can provide!

sashgorokhov commented 3 years ago

Glad it helps someone :)

For the first one, not sure what the reason can be. Can you run this in a separate notebook without any other cells but this one?

For the second one, my guess is that since pytest rewrites test module bytecode to achieve nice error messages (http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html). In case of this library, there is no module to rewrite, actually, it is just a python object so assertion rewrites are not working as expected.