line_profiler
line_profiler copied to clipboard
add @profile on method in self-defined package
I wanna test the methods written in self-defined python package, but seems like it does not work for me to add @profile mark before a method. However if I test those methods not as a package it works. Anyone can help with this?
same problem here
Are you asking about running kernprof while doing the equivalent of python -m pkg.module?
My workaround is to make the __main__ script modify the path:
import sys
import os
# EXPECTS: The current working directory is the root package directory.
# Put that on the sys path in place of this script's directory so
# module imports will work even when run via kernprof.
sys.path[0] = os.getcwd()
This might also work:
PYTHONPATH=$PWD:$PYTHONPATH kernprof -lv pkg/module