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

option to count only memory used in current thread / limit_memory("10MB", current_thread_only=True), #111

Closed
ecerulm opened this issue Mar 4, 2024 · 2 comments · Fixed by #117

Comments

@ecerulm
Copy link

ecerulm commented Mar 4, 2024

Feature Request

Currently limit_memory will count the allocations made in other threads (if I understood it right). I want an option to count only the memory allocations made on the current thread (the thread running the test code).

@pytest.mark.limit_memory("10MB", current_thread_only=True)
def test_xxxx(self):
  pass

The use case is

  • SUT is a network library (like e.g. urllib3)
  • tests require a server to connect to
  • you can create the server in a thread in the test setup
  • but you don't want to track the memory consumption in the "server" only in the SUT (the network library).

Related to #109 (comment) , In this case there are threads started for some tests that are never terminated, the allocations from those unrelated threads show as part of limit_memory on a later test. Ideally although those threads should have been terminated they should not show up in the later test.

The alternatives is to run the server outside the test framework, or use multiprocessing, both alternatives since they run the server in a different process won't show up in the limit_memory but that requires other means to control the server. When having the server as a thread you can have more tight control/communication so it's convenient.

@pablogsal
Copy link
Member

We will be working on this soon. This may require some changes in memray itself but it's doable 👍

@pablogsal
Copy link
Member

PR up: #117

ecerulm added a commit to urllib3/urllib3 that referenced this issue Aug 19, 2024
Some time ago I requested this functionality to the pytest-memray
team bloomberg/pytest-memray#111,

Now that functionality is available since `pytest-memray==1.6.0`.

Enabling `current_thread_only` will give less false positives, as memory
leaks in the server thread (which is not part of  the SUT, in this case
urllib3) will not be reported.

The need for this setting comes from #3358 where we had to modify a
bunch of test cases to properly clean up resources due to false
positives.
pquentin pushed a commit to urllib3/urllib3 that referenced this issue Aug 21, 2024
Some time ago I requested this functionality to the pytest-memray
team bloomberg/pytest-memray#111,

Now that functionality is available since `pytest-memray==1.6.0`.

Enabling `current_thread_only` will give less false positives, as memory
leaks in the server thread (which is not part of  the SUT, in this case
urllib3) will not be reported.

The need for this setting comes from #3358 where we had to modify a
bunch of test cases to properly clean up resources due to false
positives.
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

Successfully merging a pull request may close this issue.

2 participants