Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marker for fail a leaking test #45

Closed
tonybaloney opened this issue Oct 12, 2022 · 6 comments · Fixed by #52
Closed

Marker for fail a leaking test #45

tonybaloney opened this issue Oct 12, 2022 · 6 comments · Fixed by #52
Labels
enhancement New feature or request

Comments

@tonybaloney
Copy link

Feature Request

I've got some scripts using memray that run some critical code 100,000 times, I use this in the following way:

mkdir -p .profiles
PYTHONMALLOC=malloc memray run -o .profiles/memray_logrecord.py.bin -f --native memray_logrecord.py
memray flamegraph --leaks -f .profiles/memray_logrecord.py.bin
python -m http.server --directory .profiles 8000

Then I manually look at the HTML report for leaky lines and raise bugs against them. Is there any way to automate this using this pytest package?

The test script is just something like:

def do():
    # setup... 

    for _ in range(100_000):
        ... # do code things

    # assert


if __name__ == "__main__":
    do()
@gaborbernat
Copy link
Contributor

@seebi
Copy link

seebi commented Oct 19, 2022

@gaborbernat thanks for the link. Is there a way to set a default limit for all tests (without the need for adding this to all tests manually) - something like a memory base fence ...?

@gaborbernat
Copy link
Contributor

gaborbernat commented Oct 19, 2022

There is not at the moment, but PR welcome. And you can also set it to your project via a pytest hook.

@seebi
Copy link

seebi commented Oct 19, 2022

Do you have a link to an example for this as well ? :-)

@sarahmonod
Copy link

You can use any of those hooks: https://docs.pytest.org/en/7.1.x/reference/reference.html

But I would personally recommend using an autouse fixture instead: https://docs.pytest.org/en/6.2.x/fixture.html#autouse-fixtures-fixtures-you-don-t-have-to-request

@pablogsal pablogsal changed the title Question: How to fail a leaky test Marker for fail a leaking test Nov 16, 2022
@pablogsal
Copy link
Member

I'm adding a new marker in #52 for checking memory leaks. Please @tonybaloney check if this would work for your use case.

@pablogsal pablogsal added the enhancement New feature or request label Nov 16, 2022
@gaborbernat gaborbernat added help wanted Extra attention is needed and removed help wanted Extra attention is needed labels Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants