Skip to content

Commit 3658492

Browse files
authored
#40 - Force garbage collector to run between each tests
1 parent f19f3b7 commit 3658492

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

docs/sources/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Changelog
33
=========
44

5+
* :release:`1.6.1 <2021-08-23>`
6+
* :bug:`#43` Fixes a bug that prevent sending session tags correctly.
7+
* :bug:`#40` Force garbage collector to run between tests (better result accuracy)
8+
59
* :release:`1.6.0 <2021-04-16>`
610
* :feature:`#0` Support for python 3.5
711
* :feature:`#35` Better support for Doctest item.

docs/sources/configuration.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,15 @@ The following table explains how both fields are mapped:
164164

165165
Note that none of these two fields will be added if:
166166
* the CI context is incomplete
167-
* the CI context cannot be computed.
167+
* the CI context cannot be computed.
168+
169+
Parameters affecting measures
170+
-----------------------------
171+
By default, pytest-monitor runs the garbage collector prior to execute the test function.
172+
This leads to finer memory measurements. In the case where you want to disable this call to the
173+
garbage collector, you just have to set the option `--no-gc` on the command line.
174+
175+
.. code-block:: shell
176+
177+
bash $> pytest --no-gc
178+

pytest_monitor/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "1.6.0"
1+
__version__ = "1.6.1"
22
__author__ = "Jean-Sebastien Dieu"

pytest_monitor/pytest_monitor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
import gc
23
import memory_profiler
34
import pytest
45
import time
@@ -44,6 +45,8 @@ def pytest_addoption(parser):
4445
group.addoption('--component-prefix', action='store', dest='mtr_component_prefix',
4546
help='Prefix each found components with the given value (applies to all tests'
4647
' run in this session).')
48+
group.addoption('--no-gc', action="store_true", dest="mtr_no_gc",
49+
help='Disable garbage collection between tests (may leads to non reliable measures)')
4750
group.addoption('--description', action='store', default='', dest='mtr_description',
4851
help='Use this option to provide a small summary about this run.')
4952
group.addoption('--tag', action='append', dest='mtr_tags', default=[],
@@ -154,6 +157,8 @@ def prof():
154157
if not PYTEST_MONITORING_ENABLED:
155158
wrapped_function()
156159
else:
160+
if pyfuncitem.session.config.option.mtr_no_gc:
161+
gc.collect()
157162
prof()
158163
return True
159164

0 commit comments

Comments
 (0)