Skip to content

importnb causes pytest to run tests twice #160

@ddouglas87

Description

@ddouglas87

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:

cd /tmp/
mkdir project
cd project/
python3 -m venv .venv
source .venv/bin/activate
pip install pytest
mkdir tests
cd tests/
vim test.py

def test_empty():
    ...

pytest test.py -k test_empty
================================================ test session starts =================================================
platform linux -- Python 3.11.10, pytest-8.3.3, pluggy-1.5.0
rootdir: /tmp/project/tests
collected 1 item                                                                                                     

test.py .                                                                                                      [100%]

================================================= 1 passed in 0.00s ==================================================

pip install importnb

pytest test.py -k test_empty
================================================ test session starts =================================================
platform linux -- Python 3.11.10, pytest-8.3.3, pluggy-1.5.0
rootdir: /tmp/project/tests
plugins: importnb-2023.11.1
collected 2 items                                                                                                    

test.py ..                                                                                                     [ 50%]

================================================= 2 passed in 0.01s ==================================================

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:

pytest test.py -k test_empty
================================================ test session starts =================================================
platform linux -- Python 3.11.10, pytest-8.3.3, pluggy-1.5.0
rootdir: /tmp/project/tests
plugins: importnb-2023.11.2.dev11+ga633de3
collected 2 items                                                                                                    

test.py ..                                                                                                     [ 50%]

================================================= 2 passed in 0.01s ==================================================

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions