Comments (5)
Output comparison should use pytest's pretty assert repr since 0.8. See this code. If you're on a version after that, and are not seeing this, would you mind posting the (minimal) steps to reproduce that behavior?
from nbval.
Test code
We are using nbval 0.9.0.
a = 'dog'
assert a == 'cat'
pytest with pretty assertions
pytest with nbval without pretty assertions
from nbval.
So this would be using pytest for assert statements in the notebook. I'm not sure if think this is a good idea or not. It would require to special case Python kernels, and to run extra code on the kernel, meaning it should at the very least be behind a flag.
For now I would recommend you add a conf.py file in the folder of your notebooks, and use one of the collection hooks to run the needed code on the kernel. I don't know how pytest sets up its smarter assertion code for python, so I can't help you there. If you get it working, I'd be happy to help review a PR!
from nbval.
You can use ipytest
to setup assertion rewriting via AST transforms. This way the left and right hand side of the equal sign will be included in the output. However it will still not include the diffing output, you would get when running in pytest proper. (ipytest will also include this output, but currently swallows any errors so nbval would not show an error). For example:
# cell 0
import ipytest
ipytest.config.rewrite_asserts = True
# cell 1
a = 'dog'
assert a == 'cat'
# output using nbval:
# AssertionError Traceback (most recent call last)
# <ipython-input-2-2e3c346211ed> in <module>
# 1 a = 'dog'
# ----> 2 assert a == 'cat'
#
# AssertionError: assert 'dog' == 'cat'
Not sure, whether you would like to include such functionality in nbval
. If so, I am happy to extract the relevant code from ipytest
and create a PR. However, I think there is a value in putting the setup of the ast rewriting into the notebook itself and not to include it into nbval to ensure you always run the same code within the notebook frontend and nbval.
from nbval.
@chmp Thanks! It makes sense to me to have a different package for things that you use within a python notebook, compared to nbval which is used agnostically on a notebook.
[...] to ensure you always run the same code within the notebook frontend and nbval.
👍
from nbval.
Related Issues (20)
- Documentation about skipping certain output types do not work
- Pytest fails to run on a seemingly innocent unit test
- Cell numbers are off by 1 compared to what you see in the notebook
- New release please HOT 2
- Testing structural similarity rather than string identity HOT 2
- When using Sanitizer, Special Chars on notebook are not escaped
- new pytest version throws deprecation warning HOT 3
- 0.9.6: sphinx warnings
- 0.9.6: pytest is failing in few units HOT 3
- CI tests are failing HOT 1
- Many tests fail on FreeBSD HOT 1
- New release? HOT 1
- 0.10.0 release captures output even when ';' is present HOT 3
- javascript not supported? HOT 2
- 0.10.0: documentation build fails
- pytest 8.1.0 breaks nbval 0.10.0 HOT 1
- `--sanitize-with` option seems to be behaving weirdly with "newly computed (test) output"
- Parallel --dist loadscope issue HOT 1
- Sanitize replace regex HOT 2
- Testing differences across two pre-run notebooks / paths
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nbval.