Testing non-exported methods in python

My code is organized like this:

app/sampling
├── __init__.py
├── filters.py
└── test
    └── filters_test.py

There filters.pyare some exported functions (included in __init__.py) and some unexposed functions that begin with underscores.

As filters_test.pyI have no problem with testing of exported functions, I can access as follows:

from app.sampling import exported_function

(note that the "app" is part of my PYTHONPATH)

But if I try to import a private function, for example:

from ..filters import _private_function

This seems to work, but then at runtime:

SystemError: Parent module '' not loaded, cannot perform relative import

Additional notes:

  • I use my nose to run tests.
  • I would like to keep the folder structure if possible
+4
source share
1 answer

from app.sampling.filters import _private_function

+2
source

Source: https://habr.com/ru/post/1691072/


All Articles