Python change path inside submodule?
Question: I have this project structure:

    
    
    - main.py
    - app_a/
      - __init__.py
      - app.py
      - stubs/
        - app.py
    - tests/
      - test_app_a.py
    

in `main.py`, there is:

`from app_a.app import foo`

this works fine. However, when running in test environment(which can be
checked by a env variable), I need `main.py` to import from a stub module
(which is in `app_a/stubs/app.py`) instead of the real `app_a/app.py`.

Notice that I can't change `main.py` itself, I can just change the environment
before it runs.

How can I implement this? thanks.


Answer: Why not write as follows in main.py

    
    
    if env:
        from app_a.app import foo
    else:
        from app_a.stubs.app import foo
    

