pytest-profiling does not profile fixtures
See original GitHub issueConsider the following example:
import pytest
@pytest.fixture()
def work_func_fix():
s = 0
for i in range(1000):
s += i * i
return s
def work_func_test():
s = 0
for i in range(1000):
s += i * i
return s
def test_example(work_func_fix):
assert work_func_fix == work_func_test()
Apparently, only test_example
is profiled. work_func_test
appears in the profiling results, but work_func_fix
does not.
Is it a design choice? I’ve been searching but found no reference to that. Or is there a flag I should pass to enable fixture profiling?
We use pytest to test a Flask application. Fixtures create the database, and instantiate and initialize the application. We’d like to profile the initialization process but it does not appear in the results.
In fact, the profiling result in my example above shows a lot of things I don’t care about (everything that is not under test_example
), but not the fixture I do care about.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
pytest-profiling does not profile fixtures · Issue #48 - GitHub
We'd like to profile the initialization process but it does not appear in the results. In fact, the profiling result in my example...
Read more >pytest-profiling - PyPI
Profiling plugin for pytest, with tabular and heat graph output. Tests are profiled with cProfile and analysed with pstats; heat graphs are generated...
Read more >Profiling and improving the runtime of a large pytest test suite
We make heavy use of pytest's fixtures to provide tests with streamlined access to the application under test. For example the client fixture...
Read more >pytest-profiling - Python Package Health Analysis - Snyk
Looks like pytest-profiling is missing a security policy. ... Enable the fixture explicitly in your tests or conftest.py (not required when using setuptools ......
Read more >TIL How to profile Pytest tests - David Winterbottom
If you install the pytest-monitor package, then PyTest invocations will collect test profiling information in a SQLite database (called .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @lafrech - thanks for raising this and it’s definitely a valid use case. There’s a number of issues with the profiling that I’m working through at the moment and I’ll cover this as well. Your example implementation is good - we need to get the profiler turned on early enough to cover fixture execution.
I am getting different results when I profile with
cProfile
andpytest --profile
. Since I use fixtures, I think that is due to this issue. Can somebody explain why pytest-profling skips fixtures? In my case I use caching in my fixture to run subsequent tests faster.