T. Thai
T. Thai

Reputation: 21

IPython and Pytest tests conflict

In my tests folder, I have global variables and functions I want to import and use across tests.

repo
├── spam
│   ├── bacon.py
│   └── egg.py
└── eggs 
│   └── sausage.py
└── tests
     ├── spam_test.py
     ├── eggs_test.py
     └── utils.py

Say I want to import something from utils.py. I would have "from tests.utils import pan". Running the test normally works fine, but when I run in debug mode, "from tests.utils import pan" will conflict with ipython tests.

My current fix is to turn it all into fixtures and avoid importing from tests all together. Removing ipython tests from sys.path before importing from tests would also work. Another fix that may work would be to rename tests to something else, but I want to keep the tests name convention for pytest.

Is there a better solution to this problem?

I currently plan to look into conftest.py to see if anything from there may help and continue searching through google for some answers.

Upvotes: 1

Views: 76

Answers (1)

T. Thai
T. Thai

Reputation: 21

I was able to solve this by adding __init__.py to the tests folder and subfolder, so should be good now.

Upvotes: 1

Related Questions