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

Allow logs from memray core #134

Open
Clae224 opened this issue Nov 11, 2024 · 3 comments
Open

Allow logs from memray core #134

Clae224 opened this issue Nov 11, 2024 · 3 comments

Comments

@Clae224
Copy link

Clae224 commented Nov 11, 2024

I am currently unable to see any of the core memray logs when running pytest-memray with my project's test suite.

As an example, I am trying to see if support for greenlet is running inside memray when running pytest-memray, but I cannot get memray core to print or log any lines whether greenlet support is enabled or not. I have tried building memray from scratch and adding log lines and prints to both when greenlet is detected and not detected, but nothing shows up not matter how I run pytest-memray or what logging level I use. I can see the greenlet log when running pytest directly on memray without pytest-memray e.g. memray run -m pytest ... in the same environment.

Perhaps this is already implemented somewhere, but I cannot find it on the docs or see an option to enable anything like this.

Ideally there would be an option to get output from core memray code, so we can debug issues directly when using pytest-memray without having to run pytest in memray.

@godlygeek
Copy link
Contributor

Memray doesn't use the Python logging module, it instead logs by printing directly to stderr. By default pytest captures everything logged to stderr, but you can see it on the terminal if you run pytest with the -s / --capture=no flag. If you run pytest with -s in addition to --memray, you'll see the "Memray support for Greenlet is experimental" warning if your tests import the greenlet module.

You'll only see Memray's logs from the WARNING level and above, as that's the default threshold Memray sets. If you need to see logs from a lower level than that, you could apply a patch like this to pytest-memray:

diff --git a/src/pytest_memray/plugin.py b/src/pytest_memray/plugin.py
index c1f7d3d..f6fb9f8 100644
--- a/src/pytest_memray/plugin.py
+++ b/src/pytest_memray/plugin.py
@@ -3,6 +3,7 @@ from __future__ import annotations
 import collections
 import functools
 import inspect
+import logging
 import math
 import os
 import pickle
@@ -34,6 +35,7 @@ from pytest import Item
 from pytest import Parser
 from pytest import TestReport
 from pytest import hookimpl
+from memray import set_log_level

 from .marks import limit_memory
 from .marks import limit_leaks
@@ -42,6 +44,8 @@ from .utils import positive_int
 from .utils import sizeof_fmt
 from .utils import value_or_ini

+set_log_level(logging.DEBUG)
+

 class SectionMetadata(Protocol):
     long_repr: str

What are you trying to debug, specifically?

@Clae224
Copy link
Author

Clae224 commented Nov 26, 2024

Thanks, that works. I am trying to debug a segfault caused by memray interacting with greenlet which only seems to happen using pytest-memray and not memray. But I assume I should raise that in a separate issue thread?

@godlygeek
Copy link
Contributor

Yes, separate issue for that, please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants