Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

233
Visualizações
yet another query (issue ) with module hierarchy in python
mt-kart
     |
      --> src/data_kart
     |        |
     |         --> apis
     |        |       |
     |        |        --> __init__.py
     |        |        --> endpoints.py
     |        |
     |         --> models
     |        |       |
     |        |        --> __init__.py
     |        |        --> modelx.py
     |        |
     |         --> defaults.py
     |         --> main.py
      --> tests
             |
              --> __init__.py
             |
              --> conftest.py
             |
              --> test_others.py

In main.py I get module not found error when I try to refer

from defaults import func1

But this works

from .defaults import func1

It should work without "." right?

2.

From endpoints.py how should I refer the modelx.py? My prev. developer had it like below.

from data_kart.models.modelx import model1

But it complains when I run some tests using pytest from mt-kart directory. Then the below worked for pytest. But i am afraid it may give error in some different scenario.

from src.data_kart.models.modelx import model1

The project uses FastApi and OpenApI Code generators

Edit-------------------

In conftest.py I added src to sys.path and the paths are working fine for my issue 2. sys.path.append(os.getcwd()+"/src")

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You could instead add the directory including your package in PYTHONPATH, as shown here. For example, if you are on Windows, the directory of your package should look something like this: C:/users/.../mt-kart/src. After adding the path to the environment variable, please make sure to start a new terminal to lunch pytest.

By adding C:/users/.../mt-kart/src in PYTHONPATH, it means that you can import your modules like this: from data_kart.models.modelx import model1 (as your previous developer did) and from defaults import func1 should work as expected. Every time you import a module from the data_kart package, it will point to the directory given in the PYTHONPATH variable. Hence, there would be no need to add sys.path.append(... to the top of each file in your project (or test files) to import modules.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda