I have folder and code structure like this
root folder
|
|---core folder
| |
| |----transaction.py
| |
| |----executetransaction.py
|
|---test folder
|
|----test_execute_transaction.py
transaction.py
class Transaction:
def __init__(self,json):
print("in create object")
executetransaction.py
from transaction import Transaction
def execute_transaction(json):
trsobj = Transaction(json)
test_execute_transaction.py
import sys
sys.path.append("../")
from core import executetransaction
executetransaction.execute_transaction({"a":"b"})
when I execute test_execute_transaction
, it is able to import executetransaction
from core folder but I get ModuleNotFoundError: No module named 'transaction'
on the import code line in executetransaction
module.
If I runexecute_transaction({"a":"b"})
in executetransaction
module then transaction
is imported as expected and I get "in create object"
.
I have added empty __init__.py
in all folders.
This is my first time posting question here, please tell me if more details are required.