-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
importnb causes pytest to run tests twice #160
Comments
A temporary fix for this problem is to disable the importnb pytest plugin until it is fixed. This comment explains how. I chose to add the setting into my pyproject.toml file at the root of my project directory. Here's what my pyproject.toml file looks like:
The capture=no and log level are so print statements can be seen while running a test. The |
thanks for trying as a user, i feel like you would want to opt into the testing. is this what you'd expect?
are you saying the current code isn't discovering the tests. |
The most up to date version from github still has the bug in it, is what I meant to say. You can see the example output right below it that shows two tests when there should be one.
I prefer "it just works". Running tests twice is definitely a bug. As an end user I don't care under the hood how it works, via opting in or not opting in, I want it to just work. If opting in means it creates a bug, that is still an issue. I don't know if this helps, but here's how I run tests: My preference is to have a separate tests folder with their own .py files filled with tests, not to have tests in my main code base. Two reasons to do this is: 1) Tests can double as documentation. It's easier to see all the tests together when using them this way. 2) Tests can import libraries the main project does not. I have a separate requirements.txt file just for tests. My philosophy is to import a notebook like it is a .py file. I treat an .ipynb file just like a .py file. Because of this, if I'm going to write tests for a notebook, I'm putting the tests in a separate .py file in a tests folder. I will not put tests directly in the notebook itself. P.S. importnb is an AWESOME library. Ever since the functionality was added to only import functions by doing It's sad this library is not well known and not well supported. imo this should be an industry practice to do it this way, but because it's so unknown, few people even know it's an option to productionize models this way. The other import notebook python libraries work differently and imo aren't as good. |
got it. i'll take a look into the test duplication . i'll likely make importnb's pytest an opt-in feature. the original philosophy was that notebooks are used for testing ideas, so we should promote formalizing them as tests sooner. i don't agree as much anymore. the primary goal should be to import notebooks. testing is an extra feature.
hell yea. thanks for these kind words. i'm really glad those features have been useful for you. let us know if there are any public repos you are using
its cool you've seen the light. hopefully, our stoic optimism pays off and folks become more accepting of notebooks as a source code. there is a costly redundant work in translating notebooks to python that probably doesn't need to happen. |
When I
pip install importnb
individual pytests run twice.This is quite weird behavior, because importing importnb isn't required. All you have to do is pip install it and tests start running twice. When uninstalling importnb the issue goes away.
To reproduce:
Note: I've tested this with Python 3.11, 3.12, and 3.13. I've also tested it with pytest 8.3 and 8.2. This is reproducible both in PyCharm and in the command line.
Also, it doesn't work with the current version from github:
The text was updated successfully, but these errors were encountered: