pyutils / line_profiler

Line-by-line profiling for Python
Other
2.59k stars 120 forks source link

line_profiler as a pytest plugin #57

Open mgaitan opened 3 years ago

mgaitan commented 3 years ago

I frequently want to execute line_profiler for some function/code under a particular context already defined in a unittest.

So I would like to instrument something equivalent to the %lprun magic as a pytest's extension, where I can pass a list of functions to inspect in the command line before the

For instance

$ pytest --line-profiler foo.function1 --line-profiler bar.another_function_called_by_function1  tests/test_module::test_that_call_foo_function1 

would something like this be desirable?

Erotemic commented 3 years ago

If you would like to write that plugin, I think it would make a lot of sense to write is as a separate package (maybe pytest-line-profiler?) that depends on line_profiler. Because I'm not the original author, I want to keep the complexity of new additions to a minimum.

If you ensure that your package is tested, on a CI, and published on pypi, I can either give a shout-out to it in the README of this repo, or if your package is really good or becomes popular then I can add it as an optional dependency in extras_require. Thus if someone was to pip install line_profiler[pytest] that would include your package.

Let me know if you want to give it a shot, or if you don't have experience in any creating a new python package, running tests on a CI, or publishing on pypi.

mgaitan commented 3 years ago

@Erotemic pretty clear, thansk. I'll try to get some time from my employer (@shiphero) to implement this idea as an external package. I'll keep u posted.

mgaitan commented 3 years ago

I've just pushed a first version of this idea https://github.com/mgaitan/pytest-line-profiler. It would be awesome if you can try it and give me some feedback.