line_profiler icon indicating copy to clipboard operation
line_profiler copied to clipboard

add @profile on method in self-defined package

Open ba9els opened this issue 9 years ago • 2 comments

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?

ba9els avatar Apr 17 '17 06:04 ba9els

same problem here

PeterPanUnderhill avatar Jan 26 '18 09:01 PeterPanUnderhill

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

1fish2 avatar Mar 24 '18 04:03 1fish2