Reputation: 13686
In a python project, I have the following directory structure
├── cooccurrence
│ ├── cooccurrence.py
│ ├── __init__.py
├── README.md
└── tests
├── __init__.py
└── test_coccurrence.py
This leads to tests code inside my test source files having a quite ceremonial line:
from cooccurrence.cooccurrence import CoCreate
How would I simplify this overall setup if I only needed a single module, and conversely, what project structure should I have to manage multiple modules under the same package?
To test, I simply use python -m unittest discover -v
, and a solution that can also seamlessly enable using the project within PyCharm would be much appreciated.
Upvotes: 1
Views: 269
Reputation: 33946
Put the following code line in cooccurrence/__init__.py
path:
from cooccurrence import *
[Note]:
Tested on Python 2.7
Upvotes: 1
Reputation: 2169
You can import files in __init__.py
so it will be available on package level. For example you can do in cooccurrence/__init__.py
:
from cooccurrence import CoCreate
and then in your test file:
from cooccurrence import CoCreate
It will be the Pythonic way of doing so
Upvotes: 2