0

I put my pytest tests in a sub directionary called tests, in my parents directory, I have all my file in src, I try to import them using relative import but it doesn't work:

.
├── src
│   ├── __init__.py
│   └── app.py
├── tests
│   ├── __init__.py
│   └── myTests.py
└── main.py

In myTests.py

from ..src import app

This is the error I get:

    from ..src import app
E   ImportError: attempted relative import beyond top-level package

I am trying to call pytest from the top level with main.py in it:

python -m pytest -vv -x

How do I include from parent's sub directory?

Bill Software Engineer
  • 6,708
  • 20
  • 82
  • 151
  • [This post](https://stackoverflow.com/questions/30669474/beyond-top-level-package-error-in-relative-import) should answer your question. Also, check this part of the [pytest documentation](https://docs.pytest.org/en/6.2.x/goodpractices.html#tests-outside-application-code). – svex99 Feb 11 '22 at 05:10

0 Answers0