Nbdev code coverage / n-Tests

It doesn’t extract into new files… It overrides nbdev_test_nbs

Well, overrides/introduces new behavior.

1 Like

Doesn’t run for me (reported), and I don’t know how it can run for others as Config().nbs_path is indeed a string not a Path object so it doesn’t have a glob attribute?

Pete’s version is more than 1 year old, however just wrapping that in Path solves the issue. I’ve used it successfully in a project for some time now, here’s the file if you’re interested. It works very well, I was able to even include codecov in that project using Pete’s version, big shoutout to him.

2 Likes

Has anyone done mocking (unittest.mock) in Jupyter notebooks? I’m running into issues porting some code into nbdev.

There are some tests in the original codebase that leverage the @mock.patch and unittest.main(). They are simple enough to re-write without mocking. That would probably be a better approach anyways, but it got me wondering.

What is everyone’s experience so far with the use mocking in nbdev / Jupyter notebook? Haven’t seen much online.

P.S. let me know if it’d be better etiquette to start a separate post on this.

@josemz Your link seems to be broken. Do you still have your fixed file?

Alternatively how nowadays does people deal with unit test coverage under nbdev?

Hi. I don’t know of a way to do it with nbdev2, but @muellerzr did something that could be very useful here. Exporting the tests to a file or directory would allow you to use the regular pytest commands to compute the coverage.

1 Like

I tried to port @muellerzr 's 01_export.ipynb to the latest nbdev and it seems that, the latest NBProcessor() doesn’t take preprocs= anymore as its param with the following @jeremy 's commit:

How should I fix without preprocs with the latest nbdev? Any hint? The error I got is:

You can use class-based preprocessors instead. Have a look at api/10_processors.ipynb and search for def begin to see examples.