careful-dress-39510
09/20/2021, 12:43 AMpackage list command to make sure everything I expect is being packaged up.
My project structure is as so:
.
├── README.md
├── python
│   ├── db
│   │   ├── __init__.py
│   │   ├── database_adapter.py
│   │   └── database_connector.py
│   ├── sectional_model_flow.py
│   ├── __init__.py
├── requirements.txt
└── tests
    └── unit
        ├── aws
        │   ├── test_ssm.py
        │   └── test_sts.py
        └── db
            ├── test_database_adapter.py
            └── test_database_connector.py
I tried this way because metaflow doesnt like me importing say from sectional_model_flow like so from python.db.database_connector import DatabaseConnector it gives me a ModuleNotFoundError.
So I tried following the instructions here (Netflix/metaflow#175), and this allowed it to run, but now my tests can't run because the import above would change to from db.database_connector import DatabaseConnector
What am I missing, why does this behave so differently to normal python implementations?straight-shampoo-11124
09/20/2021, 12:48 AMcareful-dress-39510
09/20/2021, 12:49 AMcareful-dress-39510
09/20/2021, 12:49 AMmodule eg db not foundcareful-dress-39510
09/20/2021, 12:50 AMpython.db.....straight-shampoo-11124
09/20/2021, 12:52 AMPYTHONPATH points at the root, from python.db.database_connector import DatabaseConnector should work in tests and in sectional_model_flow.py you can do from db.database_connector import DatabaseConnectorstraight-shampoo-11124
09/20/2021, 12:53 AMpytest doesn't run sectional_model_flow.pycareful-dress-39510
09/20/2021, 12:54 AMdatabase_connector file as an example ( I left the other files out for simplicity ). So when testing this file it can work for the flow and not the testsstraight-shampoo-11124
09/20/2021, 12:57 AMfrom . import database_adapter or something like it?straight-shampoo-11124
09/20/2021, 12:57 AMcareful-dress-39510
09/20/2021, 12:58 AMdatabase_adapter.py
it imports it with from aws.ssm import Ssm
This valid in the flow, but in the test it needs from python.aws.ssm import Ssmcareful-dress-39510
09/20/2021, 1:01 AMPYTHONPATH="./python" pytestcareful-dress-39510
09/20/2021, 1:01 AMstraight-shampoo-11124
09/20/2021, 1:05 AMpython in your case, so that should work.
You could make tests see the same universe by setting PYTHONPATH=python but if you don't want to do that, you'd need to change imports to that they are relative and not absolutestraight-shampoo-11124
09/20/2021, 1:05 AMaws under db?careful-dress-39510
09/20/2021, 1:06 AMcareful-dress-39510
09/20/2021, 1:06 AMcareful-dress-39510
09/20/2021, 1:06 AMstraight-shampoo-11124
09/20/2021, 1:10 AMpython, so you would have somepkg/db and somepkg/aws then in db you can do from ..aws.ssm import Ssmstraight-shampoo-11124
09/20/2021, 1:10 AMtests can do from python.somepkg.db.database_connector import DatabaseConnector and it should work okstraight-shampoo-11124
09/20/2021, 1:11 AMPYTHONPATH for tests - either approach should workcareful-dress-39510
09/20/2021, 1:12 AMstraight-shampoo-11124
09/20/2021, 1:13 AM