Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

testing non-exported methods in python

My code is organized this way:

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

On filters.py there are some exported functions (included in __init__.py) and some unexported functions, that begin with underscore.

On filters_test.py I have no trouble testing the exported functions, that I can access like this:

from app.sampling import exported_function

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

But then if I try to import a private function like this:

from ..filters import _private_function

This seems to work but then on runtime:

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

Additional notes:

  • I'm using nose for running the tests
  • I'd like to keep the folder structure if possible
like image 458
Pablo Fernandez Avatar asked Dec 19 '17 21:12

Pablo Fernandez


1 Answers

from app.sampling.filters import _private_function

like image 185
Krzysztof Słowiński Avatar answered Oct 16 '22 10:10

Krzysztof Słowiński