question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pytest-profiling does not profile fixtures

See original GitHub issue

Consider 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
eeastoncommented, Mar 8, 2018

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.

0reactions
mehdisadeghicommented, Nov 29, 2017

I am getting different results when I profile with cProfile and pytest --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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found