rkern / line_profiler

(OLD REPO) Line-by-line profiling for Python - Current repo ->
https://github.com/pyutils/line_profiler
Other
3.6k stars 254 forks source link

add @profile on method in self-defined package #88

Open ba9els opened 7 years ago

ba9els commented 7 years ago

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?

PeterPanUnderhill commented 6 years ago

same problem here

1fish2 commented 6 years ago

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