1

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.

1
  • In this case, I would just shorten the name of the package :) Commented Jan 30, 2018 at 7:25

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

Put the following code line in cooccurrence/__init__.py path:

from cooccurrence import *

[Note]:

Tested on Python 2.7

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.